MVVM - Control color of area series on dynamically generated graph

4 posts, 0 answers
  1. Tarun
    Tarun avatar
    6 posts
    Member since:
    Jan 2012

    Posted 15 Mar 2014 Link to this post

    I am generating 2 to 4 area series dynamically by referring below link from telerik documentation:

    http://www.telerik.com/help/wpf/radchartview-features-chartseriesprovider.html

    But these dynamic area series are showing default colors.

    Is there a property I could use to control the color of dynamically generated Area series? My application is using MVVM pattern. 
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 19 Mar 2014 Link to this post

    Hello Tarun,

    You can bind the Fill property of the AreaSeries via Style. In order to follow the MVVM pattern you can implement a Converter to change the color of the series. We prepared a sample project based on the mentioned help article and added such Converter class which selects a Brush depending on a property from the AreaSeries's ViewModel.

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
           {
               var series = value as SeriesProviderDataItem;
               if (series != null)
               {
                   if (series.SeriesName == "SerieA")
                   {
                       return ABrush;
                   }
                   else if (series.SeriesName == "SerieB")
                   {
                       return BBrush;
                   }
                   else
                       return CBrush;
               }
               return null;

    Please examine the provided solution and let us know if you need any further assistance.

    Regards,
    Boris Penev
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dev
    Dev avatar
    6 posts
    Member since:
    Feb 2009

    Posted 20 Mar 2014 in reply to Boris Link to this post

    Hi Boris,

    I tried your solution but it is also taking default colors and not showing the colors you are assigning through converter.
    Can you please check it?


    Regards,
    Dev
  5. Boris
    Admin
    Boris avatar
    276 posts

    Posted 25 Mar 2014 Link to this post

    Hello Dev,

    You may get different colors if you use older version of telerik control binaries - for example Q3 2013.
    Attached you can find a project with our latest Q1 2014 binaries where the colors are shown as in the attached picture.

    Regards,
    Boris Penev
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
Back to Top