MVVM SeriesProvider with PointSeries, using BitmapRenderOptions. How to set the color of the points?

5 posts, 1 answers
  1. James
    James avatar
    7 posts
    Member since:
    Jul 2012

    Posted 03 Nov 2014 Link to this post

    I have implemented a chart which displays a dynamic set of series (displayed as points), using BitmapRenderOptions with a SeriesProvider in an MVVM environment.  However, I have been unable to figure out how to control the color of each series.  The color of the series lives in each DataObject instance in the ChartSeriesProvider Source collection.

    I have been able to set the color of the series based on this value if I chart the data as a LineSeries (by setting the Stroke property in the LineSeries style within the CategoricalSeriesDescriptor.Style declaration), but I haven't found a solution for PointSeries' yet.  In other charts in the project (that don't require a SeriesProvider), I have been able to set the color for the point series via PointSeries.DefaultVisualStyle.

    I am able to get each series to be a different color using a palette, but since I need the series to match a specific color, even a custom palette wouldn't work (as I have no way to link the correct color to the series).

    I know that I can't use a PointTemplate, as I want/need the BitmapRenderOptions, so how do I bind the color?  I know there must be a simple solution that I'm missing!

    Thanks
  2. Answer
    Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 04 Nov 2014 Link to this post

    Hi James,

    I think that the easiest way to go here is to use a converter. You need to again set the DefaultVisualStyle, as you have already done in your other projects. The little difference is that the style now depends on a brush that is in your series-view-model entity. So, you will need to use a converter:
    <telerik:CategoricalSeriesDescriptor CategoryPath="XCat" ValuePath="YVal" ItemsSourcePath="Data">
     <telerik:CategoricalSeriesDescriptor.Style>
      <Style TargetType="telerik:PointSeries">
       <Setter Property="DefaultVisualStyle" Value="{Binding PointFill, Converter={StaticResource FillToPathStyleConverter}}" />

    I have attached a small project to demonstrate this. I hope this helps.

    Regards,
    Petar Marchev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. James
    James avatar
    7 posts
    Member since:
    Jul 2012

    Posted 04 Nov 2014 in reply to Petar Marchev Link to this post

    Thanks, that did the trick, much appreciated!
  5. James
    James avatar
    7 posts
    Member since:
    Jul 2012

    Posted 04 Nov 2014 in reply to Petar Marchev Link to this post

    Thanks, that did the trick, much appreciated!
  6. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 05 Nov 2014 Link to this post

    Hi James,

    We are glad that we were able to help. Don't forget to set the DefaultVisualsRenderMode property of the render options to Batch (information here).

    Regards,
    Petar Marchev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready