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

Coordinating Color Between RadLegend and RadCartesianChart

3 Answers 228 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 15 Apr 2014, 08:02 PM
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...

 <telerik:RadCartesianChart.SeriesProvider>   
    <
telerik:CategoricalSeriesDescriptor.Style 
       <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:AreaSeries.LegendSettings>
         <telerik:SeriesLegendSettings Title="MyTitle" />
 </telerik:AreaSeries.LegendSettings>

If you can include or point me to a WPF example (preferably not a silverlight one), that would be really helpful. Thanks.
 
 

3 Answers, 1 is accepted

Sort by
0
Terry
Top achievements
Rank 1
answered on 15 Apr 2014, 08:18 PM
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}" /> 
0
Terry
Top achievements
Rank 1
answered on 15 Apr 2014, 08:41 PM
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.   
0
Petar Marchev
Telerik team
answered on 18 Apr 2014, 03:05 PM
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.

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.

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