How do you change the Font Color for the legend?

6 posts, 0 answers
  1. Gilberto
    Gilberto avatar
    6 posts
    Member since:
    Apr 2009

    Posted 19 May 2009 Link to this post

    Hello,

    I am wondering if there is a way to change the font color for the Legend.  I have no idea where i would do that or how.  Any help would be appreciated.
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 22 May 2009 Link to this post

    Hi Gilberto,

    We have attached a sample code snippet that demonstrates how to change the LegendItem text color to Yellow via setting the ChartLegend.LegendItemStyle property (you need to define the custom style you will be applying as a resource and then set it from code behind to the ChartLegend.LegendItemStyle property):

    XAML
    <UserControl x:Class="SilverlightApplication9.Page"  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
        xmlns:control="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"   
        xmlns:chart="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting">  
        <Grid x:Name="LayoutRoot" Background="White">  
            <Grid.Resources>  
            <Style x:Name="CustomStyle" TargetType="chart:ChartLegendItem">  
                <Setter Property="Template" >  
                    <Setter.Value>  
                    <ControlTemplate TargetType="chart:ChartLegendItem">  
                        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">  
                            <Grid.ColumnDefinitions>  
                                <ColumnDefinition Width="Auto" />  
                                <ColumnDefinition />  
                            </Grid.ColumnDefinitions>  
                            <Rectangle x:Name="PART_LegendItemMarker"  
                                        Height="15"   
                                        Width="30"  
                                        StrokeThickness="1"  
                                        RadiusX="2"  
                                        RadiusY="2"  
                                        HorizontalAlignment="Left"   
                                        VerticalAlignment="Bottom"  
                                        Margin="0,0,0,5"  
                                        Style="{TemplateBinding ItemStyle}" />  
                            <TextBlock  
                                        Grid.Column="1"  
                                        Padding="0"  
                                        Margin="5,5,5,7"  
                                        VerticalAlignment="Center"  
                                        Height="14"    
                                        Foreground="Yellow"  
                                        Text="{TemplateBinding Label}" />  
                        </Grid>  
                    </ControlTemplate>  
                    </Setter.Value>  
                </Setter>  
            </Style>  
            </Grid.Resources>  
      
            <control:RadChart x:Name="RadChart1" />  
              
        </Grid>  
    </UserControl>  

    C#
    using System.Windows.Controls;  
    using Telerik.Windows.Controls.Charting;  
      
    namespace SilverlightApplication9  
    {  
        public partial class Page : UserControl  
        {  
            public Page()  
            {  
                InitializeComponent();  
      
                DataSeries series = new DataSeries();  
                series.Add(new DataPoint(20));  
                series.Add(new DataPoint(30));  
                series.Add(new DataPoint(40));  
                series.Add(new DataPoint(80));  
                series.Add(new DataPoint(10));  
                series.Add(new DataPoint(50));  
                series.Add(new DataPoint(40));  
                series.Add(new DataPoint(20));  
                series.Add(new DataPoint(90));  
      
                series.Definition = new LineSeriesDefinition();  
      
                RadChart1.DefaultView.ChartArea.DataSeries.Add(series);  
                RadChart1.DefaultView.ChartLegend.LegendItemStyle = this.CustomStyle;  
            }  
        }  
    }  
      


    Hope this helps.


    Kind regards,
    Manuel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Larry
    Larry avatar
    1 posts
    Member since:
    Jun 2009

    Posted 30 Jun 2009 Link to this post

    I have implemented this as you have indicated and all worked well... except the legend title.  What are the steps to changing the legend title?
  4. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 01 Jul 2009 Link to this post

    Hi Larry,

    We would suggest you to review this help article here that explains how to customize the appearance of the ChartLegend.

    Hope this helps.


    Regards,
    Manuel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Grtjn
    Grtjn avatar
    129 posts
    Member since:
    Feb 2010

    Posted 01 Apr 2010 Link to this post

    Hi Manuel,

    How can I change the color of the background of the legenditems ?
    Is this possible using a style ?

    Kind regards,

    Gertjan
  6. Velin
    Admin
    Velin avatar
    391 posts

    Posted 06 Apr 2010 Link to this post

    Hi Grtjn,

    Please, find the answer of your question in the other thread you have opened.

    Sincerely yours,
    Velin
    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.
Back to Top