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.
Unfortunately, activation email could not send to your email. Please try again.

Change SfChart:LineSeries label style (color, font)

Thread ID:

Created:

Updated:

Platform:

Replies:

131336 Jul 5,2017 09:08 AM Jul 10,2017 02:52 AM WPF 5
loading
Tags: SfChart
Yacine Atoini
Asked On July 5, 2017 09:08 AM

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;



Durgadevi Selvaraj [Syncfusion]
Replied On July 6, 2017 04:31 AM

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
 


Yacine Atoini
Replied On July 6, 2017 07:29 AM

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.


Durgadevi Selvaraj [Syncfusion]
Replied On July 7, 2017 07:07 AM

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 


Yacine Atoini
Replied On July 7, 2017 07:52 AM

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

Yacine.


Durgadevi Selvaraj [Syncfusion]
Replied On July 10, 2017 02:52 AM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;