Coordinating Color Between RadLegend and RadCartesianChart

4 posts, 0 answers
  1. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 15 Apr 2014 Link to this post

    I have a RadCartesianChart that I am binding with a set of various series. One set of series is for a collection of dynamic items (do not know ahead of time how many) and I am using "telerik:RadCartesianChart.SeriesProvider" and referencing the collection of dynamic elements using the ItemSource property. The other series are known ahead of time and I bind those directly to the chart using a named property in my view model. The chart displays the various series correctly.

    My problem involves the radLegend. How do I bind my legend to both the items in the dynamic series and the named property so that the colors match? 

    What I need is a clear example where a series provider makes use of the LegendSettings property. I am trying this, but it does not work...

           <Setter Property="LegendSettings" Value="{Binding name}"/>

    Elsewhere, the following is working in a regular series. Can I have both types of binding for a single RadLegend?

             <telerik:SeriesLegendSettings Title="MyTitle" />

    If you can include or point me to a WPF example (preferably not a silverlight one), that would be really helpful. Thanks.
  2. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 15 Apr 2014 in reply to Terry Link to this post

    An edit to the above. Another option is if I can set my color (for the dynamic series defined in the SeriesProvider) with a call to an object that specifies the color to set for the value. Perhaps a function that takes a string (i.e. name) and returns a color. Something like:

    <Setter Property="Fill" Value="{Binding name,  Converter=MyFillBrushConverter}" /> 
  3. DevCraft R3 2016 release webinar banner
  4. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 15 Apr 2014 in reply to Terry Link to this post

    Follow-up. I got this working more or less with code-behind and a converter. If I define my converter like the following:

    <Setter Property="Fill" Value="{Binding name,  Converter={StaticResource MyBrushConverter}}" /> 

    My converter object and the Convert method returns an object that is a Brush (i.e. what the Fill property requires). This allows me to set the SeriesProvider dynamic area series deterministically and I can coordinate the items in my RadLegend with code behind using the same converter.

    This may be the solution, but still interested in other ways such as a purely declarative approach.   
  5. Petar Marchev
    Petar Marchev avatar
    968 posts

    Posted 18 Apr 2014 Link to this post

    Hi Terry,

    In order for the chart to produce legend items for a series, you need to set the LegendSettings property to a corresponding value. In you example you set it to a string, which will not work. You need to set the legend settings accordingly. This means that if you want to have a different Title for each series, you need to create a new SeriesLegendSettings for each series, and assign the Title property to each legend settings object.

    Once you do this, you should have absolutely no problem with the legend items' colors. The chart does this automatically, it will assign the legend item the same brush that is used for the series' path fill. Make sure you are using the latest binaries (last SP) because we had a bug in the Q1 official release that lead to legend items with no colors, but this is now fixed.

    I have attached a small app to demonstrate this.

    Petar Marchev

    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