Set Series Label Color in Chart Legend

6 posts, 0 answers
  1. Daniel
    Daniel avatar
    8 posts
    Member since:
    Jul 2010

    Posted 28 Oct 2010 Link to this post

    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)
  2. Daniel
    Daniel avatar
    8 posts
    Member since:
    Jul 2010

    Posted 29 Oct 2010 Link to this post

    Not possible?
  3. DevCraft banner
  4. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 02 Nov 2010 Link to this post

    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
  5. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 02 Dec 2010 Link to this post

    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
  6. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 07 Dec 2010 Link to this post

    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
  7. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 07 Dec 2010 Link to this post

    Works beautifully! Thanks!
Back to Top
DevCraft banner