SfChart chart = new SfChart() ; chart.Legend = new ChartLegend() {FontSize = 15, FontStyle = FontStyles.Italic, Foreground = new SolidColorBrush(Colors.Red) }; |
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.
<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> |
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(); } } |
Great !
It works perfectly. Thanks a lot for your help :)
Yacine.