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

Legend MarkerFill Color linked to series Color

2 Answers 43 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Olivier Masset
Top achievements
Rank 1
Olivier Masset asked on 08 Nov 2011, 03:39 PM
Hello,
I'm working on a MVVM application.
The user can dynamically change the RadChart series color with the interface.

Code behind:
        ...
Binding strokeBinding = new Binding(".")
{
 Source = dataSerie,
 Mode = BindingMode.OneWay,
 Path = new PropertyPath("Color"),
 Converter = new ColorToBrushConverter()
};

BindingOperations.SetBinding(appearanceSettings, AppearanceSettings.StrokeProperty, strokeBinding);
        ...

The legend is automatically generated but colors do not change automatically with the series color.
I tried to turn auto genarated items to false and used a binding between the color and the legend MarkerFillProperty.
It sets the marker with the right color but if I change dynamically the color it doesn't work.

Code behind:
ChartLegend.UseAutoGeneratedItems = false;

   ...

ChartLegendItem chartLegendItem = new ChartLegendItem();
chartLegendItem.Label = dataSerie.LegendLabel;

Binding markerFillBinding = new Binding(".")
{
 Source = dataSerie,
 Mode = BindingMode.OneWay,
 Path = new PropertyPath("Color"),
 Converter = new ColorToBrushConverter()
};


Could you help me?
Regards,
Olivier


2 Answers, 1 is accepted

Sort by
0
Olivier Masset
Top achievements
Rank 1
answered on 08 Nov 2011, 03:43 PM
sorry I forgot the end of the source code:

Code behind:
ChartLegend.UseAutoGeneratedItems = false;

   ...

ChartLegendItem chartLegendItem = new ChartLegendItem();
chartLegendItem.Label = dataSerie.LegendLabel;

Binding markerFillBinding = new Binding(".")
{
 Source = dataSerie,
 Mode = BindingMode.OneWay,
 Path = new PropertyPath("Color"),
 Converter = new ColorToBrushConverter()
};

BindingOperations.SetBinding(chartLegendItem, ChartLegendItem.MarkerFillProperty, markerFillBinding);
//chartLegendItem.MarkerFill = new SolidColorBrush(Colors.Blue);
trend.DefaultView.ChartLegend.Items.Add(chartLegendItem);

0
Sia
Telerik team
answered on 11 Nov 2011, 04:52 PM
Hi Olivier Masset,

Please check the approach which my colleague described in the following forum thread and let me know whether it works for your scenario.

If not please open a support ticket and send us a runnable project showing your exact scenario so that we can give you a more specific solution.
Thank you in advance.

Kind regards,
Sia
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Olivier Masset
Top achievements
Rank 1
Answers by
Olivier Masset
Top achievements
Rank 1
Sia
Telerik team
Share this question
or