We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Change SfChart:LineSeries label style (color, font)

Hello,

I am trying to change the label of my SfChart:LineSeries style (color and font) but I don't find who.
Could you please help me ?
Thanks in advance.

See below my code:

LineSeries myLineSeries = new LineSeries();

myLineSeries.ShowEmptyPoints = true;
myLineSeries.ItemsSource = itemSourceMyLineSeries;
myLineSeries.XBindingPath = "X";
myLineSeries.YBindingPath = "Y";
myLineSeries.StrokeThickness = 1.5;
myLineSeries.Interior = myColor;
myLineSeries.Label = myLabel;



5 Replies

DS Durgadevi Selvaraj Syncfusion Team July 6, 2017 08:31 AM UTC

Hi Yacine, 
 
Thanks for contacting Syncfusion Support. 
 
We can achieve your requirement of changing color and font for the series label(Chart Legend label) by using the FontSize and Foreground property in  chart legend as shown in the below code snippet, 
 
SfChart chart = new SfChart() ; 
chart.Legend = new ChartLegend() {FontSize = 15, FontStyle = FontStyles.Italic, Foreground = new SolidColorBrush(Colors.Red) }; 
 
 
Please find the output screenshot, 
 
 
We have prepared a demo sample for your reference and please downloaded from the below link, 

  
Regards,  
Durgadevi S
 



YA Yacine Atoini July 6, 2017 11:29 AM UTC

Thank you for your prompt answer.

If I have several LineSeries, so several elements in my legend, is it possible to change easily the style of only one of them  ?

Regards,

Yacine.



DS Durgadevi Selvaraj Syncfusion Team July 7, 2017 11:07 AM UTC

Hi Yacine, 

Thanks for your update, 

We can achieve your requirement of changing style for only one legend item in ChartLegend by using converter to the ContentPresenter of  ItemTemplate in ChartLegend  as like in the below code snippet,  

Xaml: 
  <Grid.Resources> 
            <local:LabelConverter x:Key="labelConv"/> 
            
            <DataTemplate x:Key="legendTemplate"> 
                
                <StackPanel Orientation="Horizontal" Margin="5" > 
                    <Grid> 
                        <ContentPresenter Width="{Binding IconWidth}" Height="{Binding IconHeight}" Content="{Binding}"  
                                              Visibility="{Binding IconVisibility}" Margin="2"  
                                          ContentTemplate="{Binding LegendIconTemplate}"> 
                        </ContentPresenter> 
                    </Grid> 
                    <ContentPresenter Content="{Binding Converter={StaticResource labelConv}}"/> 
                </StackPanel> 
               
            </DataTemplate> 
        </Grid.Resources> 
 


<chart:SfChart.Legend> 
     <chart:ChartLegend ItemTemplate="{StaticResource legendTemplate}" /> 
 
  </chart:SfChart.Legend> 

C#: 
 
public class LabelConverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            var legendItem = value as LegendItem; 
            TextBlock textblock = new TextBlock(); 
            textblock.Text = (value as LegendItem).Label; 
            textblock.FontSize = 13; 
 
            if (legendItem.Label == "Series2") 
            { 
                textblock.Foreground = legendItem.Interior; 
                textblock.FontStyle = FontStyles.Italic; 
                textblock.FontWeight = FontWeights.Bold; 
            } 
 
            return textblock; 
        } 
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            throw new NotImplementedException(); 
        } 
    } 
 
 
 
Please find the output Screenshot, 
  
We have prepared the sample based on your requirement and it can be downloaded from the below link, 


Regards,  
Durgadevi S 



YA Yacine Atoini July 7, 2017 11:52 AM UTC

Great !
It works perfectly. Thanks a lot for your help :)

Yacine.



DS Durgadevi Selvaraj Syncfusion Team July 10, 2017 06:52 AM UTC

Hi Yacine, 
 
We glad to know that the issue has been resolved and please let us know if you need any further assistance on this. 
 
Regards,  
Durgadevi S 


Loader.
Up arrow icon