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

RadChart, SeriesMappingCollection MVVM binding doesn't work.

1 Answer 97 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 31 May 2013, 11:41 AM
Hello
I am a newbie in WPF RadChart. Currently I am doing a project where data will be displayed in stacked bar chart. I bound SeriesMappingCollection ViewModel property to SeriesMapping xaml property but it seems works only once (when viewmodel is instantiated)
I am unable to force chart to redraw itself when SeriesMappingCollection is feed with new portion of data.

XAML:
<telerik:RadChart
                        x:Name="DefectChart"
                        Grid.Row="1"
                        SeriesMappings="{Binding DiagramMappings}">
</telerik:RadChart>

ViewModel:
SeriesMappingCollection _mappings;
public SeriesMappingCollection DiagramMappings
{
    get
    {
        if (_mappings == null)
        {
            _mappings = new SeriesMappingCollection();
            var temp = new SeriesMappingCollection();
 
            var sm = new SeriesMapping();
            sm.SeriesDefinition = new StackedBarSeriesDefinition();
            sm.ItemMappings.Add(new ItemMapping("Category", DataPointMember.XCategory));
            sm.ItemMappings.Add(new ItemMapping("Data", DataPointMember.YValue));
            sm.ItemsSource = new List<ChartData>()
    {
        new ChartData("C1", 1),
        new ChartData("C2", 5),
        new ChartData("C3", 7)
    };
 
            temp.Add(sm);
 
            var sm2 = new SeriesMapping();
            sm2.SeriesDefinition = new StackedBarSeriesDefinition();
            sm2.ItemMappings.Add(new ItemMapping("Category", DataPointMember.XCategory));
            sm2.ItemMappings.Add(new ItemMapping("Data", DataPointMember.YValue));
            sm2.ItemsSource = new List<ChartData>()
    {
        new ChartData("C1", 10),
        new ChartData("C2", 7),
        new ChartData("C3", 18)
    };
            temp.Add(sm2);
            this._mappings = temp;
        }
        return _mappings;
    }
    set
    {
        _mappings = value;
        NotifyOfPropertyChange(() => DiagramMappings);
    }
}

in getter I am using the mocked data, and this is drawn on chart, but after update of the SeriesMappingCollection next time chart doesn't reflect any changes.


Mocked chart data (btw taken from on of your examples)

public class ChartData
    {
        public ChartData(string c, double d)
        {
            this.Category = c;
            this.Data = d;
        }
 
        public string Category { get; set; }
        public double Data { get; set; }
    }


Thanks in advance for help.
Regards

1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 04 Jun 2013, 07:50 AM
Hello Adam,

I created a test project based on your code and I can confirm that there is a bug in the control. I have logged it in our PITS where you can vote for it and track its status. I have updated your Telerik points for pointing this issue to us. As a work-around I can suggest that you do not changed the collection property but only modify the collection. I have attached a project to demonstrate this.

I want to also direct you to our new charting solution - the ChartView. It is a newer control with a greater performance rate and is generally more flexible than the old RadChart. However, note that with the ChartView you cannot bind the series to the view model the same way you can in RadChart, perhaps you can use the SeriesProvider to get the job done.

Regards,
Petar Marchev
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ChartView
Asked by
Adam
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or