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

Set Series Label Color in Chart Legend

5 Answers 543 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 28 Oct 2010, 11:58 PM
I need to programmatically change the series legend label color.

See:
http://i.imgur.com/kWYNT.png

How do I change that to a different color in my codebehind? (no XAML please. I am not hardcoding a different style for every color)

5 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 29 Oct 2010, 06:40 PM
Not possible?
0
Evgenia
Telerik team
answered on 02 Nov 2010, 09:02 AM
Hi Daniel,

To be able to change Legend Item Marker's color you can manually generate legend items for the chart legend and then set custom color for them with item.Background property. This is shown in our help topic - http://www.telerik.com/help/silverlight/radchart-features-chart-legend.html (Manual Legend Items Generation).
Have in mind that using this approach you will change Item Markers colors but that won't affect Series colors (they will stay the default ones).

Greetings,
Evgenia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jeremy
Top achievements
Rank 1
answered on 03 Dec 2010, 03:38 AM
Hi

I am trying to do exactly the same thing dynamically and here is my code from following the above demo:
ChartLegendItem lgnd = new ChartLegendItem();
lgnd.Label = myObject.seriesName;
lgnd.Background = new SolidColorBrush(myObject.seriesColour);
MyChartLegend.Items.Add(lgnd);

But it doesn't work! It sets the background colour of the legend label instead (pic attached). I've got the latest version (2010.Q3.1110), what am I doing wrong?

Also would like to know how to hide the legend header

Edit: sorry, it won't let me attach a 30K jpg
0
Evgenia
Telerik team
answered on 07 Dec 2010, 03:29 PM
Hello Jeremy,

You are doing everything right. The problem is that in our latest version of RadChart 2010.3.1110 we added new property MarkerFill which will Change the LegendItemMarkers color. Background property which you tried is changing the LegendI tems Background. Here is how your code should look like when using our latest version:

RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = false;
            ChartLegendItem item1 = new ChartLegendItem();
            item1.Label = "Item 1";
            item1.MarkerFill = new SolidColorBrush(Colors.Blue);
            RadChart1.DefaultView.ChartLegend.Items.Add(item1);
            ChartLegendItem item2 = new ChartLegendItem();
            item2.Label = "Item 2";
            item2.MarkerFill = new SolidColorBrush(Colors.Green);
            RadChart1.DefaultView.ChartLegend.Items.Add(item2);

It seems that our documenation article is not updated with the latest changes. The responsible people are notified and this will be fixed soon.

To be able to remove the Legend Header you should set empty string to Header property:
RadChart1.DefaultView.ChartLegend.Header = String.Empty;

Kind regards,
Evgenia
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Jeremy
Top achievements
Rank 1
answered on 08 Dec 2010, 12:39 AM
Works beautifully! Thanks!
Tags
Chart
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Evgenia
Telerik team
Jeremy
Top achievements
Rank 1
Share this question
or