This is a migrated thread and some comments may be shown as answers.

Databinding SeriesMapping and seriesmapping to different data sources

2 Answers 75 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Morten Post
Top achievements
Rank 1
Morten Post asked on 23 Sep 2011, 03:02 PM
Hello,

I have a radchart that I wish to add x series to dynamically depending on what you check off in a checkbox list.

I have a RadChart declared like this:
<telerik:RadChart x:Name="radChart" telerik:StyleManager.Theme="Metro" SeriesMappings="{Binding ChartSeriesMapping}" >
            </telerik:RadChart>

My ChartSeriesMapping is declaredl like this:
private SeriesMappingCollection _chartSeriesMapping;
public SeriesMappingCollection ChartSeriesMapping
{
    get
    {
        return _chartSeriesMapping;
    }
    set
    {
        if (_chartSeriesMapping != value)
        {
            _chartSeriesMapping = value;
            this.OnPropertyChanged("ChartSeriesMapping");
        }
    }
}

I'm adding series like this:
SeriesMapping salesAmountMapping = new SeriesMapping();
salesAmountMapping.LegendLabel = p.StoreName;
 
salesAmountMapping.ItemsSource = report.ChartData;
salesAmountMapping.SeriesDefinition = new BarSeriesDefinition();
 
salesAmountMapping.ItemMappings.Add(new ItemMapping("XValue", DataPointMember.XValue));
salesAmountMapping.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
 
report.ChartSeriesMapping.Add(salesAmountMapping);
Where ChartData is containing XValue and YValue public properties.

But the charts is always empty when I'm adding new series... How is this supposed to work? Also, how come legend Label is always set to Series 0, Series 1, etc?

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Morten Post
Top achievements
Rank 1
answered on 23 Sep 2011, 03:33 PM
Edit:

I've looked a bit more into this. It seems like the RadChart is never databinding, which I find quite odd:


So Why isn't SeriesMappings binding? ItemsSource is but not SeriesMappings :-(

 <telerik:RadChart telerik:StyleManager.Theme="Metro" SeriesMappings="{Binding Path=ChartSeriesMapping}" DataBinding="RadChart_DataBinding"/>

But if I add ItemsSource={Binding...} it works. 

DataTemplate looks like this:

<DataTemplate x:Key="TouchReportTemplate">
            <Grid>
                <telerik:RadChart x:Name="myRadChart2" DataContext="MyReport" telerik:StyleManager.Theme="Metro" UseDefaultLayout="False" SeriesMappings="{Binding ChartSeriesMapping}">
                    <telerik:ChartArea x:Name="ChartArea1" EnableAnimations="True"></telerik:ChartArea>
                </telerik:RadChart>
</Grid>
</DataTemplate>

And is used here:

<s:ScatterView x:Name="myScatterView" ItemTemplateSelector="{StaticResource ReportTemplateSelector}" ItemsSource="{Binding Reports}" >
    <s:ScatterView.ItemContainerStyle>
        <Style TargetType="s:ScatterViewItem">
            <Setter Property="MinWidth" Value="400" />
            <Setter Property="MinHeight" Value="300" />
            <Setter Property="MaxWidth" Value="800" />
            <Setter Property="MaxHeight" Value="700" />
            <EventSetter Event="s:ScatterViewItem.PreviewTouchMove" Handler="ScatterViewItem_PreviewTouchMove" />
            <EventSetter Event="s:ScatterViewItem.PreviewTouchUp" Handler="ScatterViewItem_PreviewTouchUp" />
        </Style>
    </s:ScatterView.ItemContainerStyle>
</s:ScatterView>



0
Yavor
Telerik team
answered on 28 Sep 2011, 10:54 AM
Hi Morten Post,

Indeed, there is a problem in this scenario. It is logged in our Public Issue Tracking System, so you can track its status here. Did you try wrapping the RadChart in your DataTemplate into a UserControl as a workaround to this issue?

Kind regards,
Yavor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Morten Post
Top achievements
Rank 1
Answers by
Morten Post
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or