RadChart, SeriesMappingCollection MVVM binding doesn't work.

2 posts, 0 answers
  1. Adam
    Adam avatar
    1 posts
    Member since:
    May 2013

    Posted 31 May 2013 Link to this post

    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
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 04 Jun 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top