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

How do you change the Font Color for the legend?

5 Answers 332 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Gilberto
Top achievements
Rank 1
Gilberto asked on 19 May 2009, 07:03 PM
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.

5 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 22 May 2009, 12:39 PM
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.
0
Larry
Top achievements
Rank 1
answered on 30 Jun 2009, 07:47 PM
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?
0
Giuseppe
Telerik team
answered on 01 Jul 2009, 02:38 PM
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.
0
Grtjn
Top achievements
Rank 1
answered on 01 Apr 2010, 08:22 AM
Hi Manuel,

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

Kind regards,

Gertjan
0
Velin
Telerik team
answered on 06 Apr 2010, 08:26 AM
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.
Tags
Chart
Asked by
Gilberto
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Larry
Top achievements
Rank 1
Grtjn
Top achievements
Rank 1
Velin
Telerik team
Share this question
or