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

Legend text color

It is a problem in my app that the legend text color only can be black. It looks like in the xamarin version you can set 

ChartLegendLabelStyle text color to what you wish. When will that be possible in the .nat mau version ?



--

Eigil


2 Replies

SS Sowndharya Selladurai Syncfusion Team April 3, 2023 07:10 AM UTC

Hi Eigil,

Yes, it is possible to change the text color of the legend in MAUI by setting the ItemTemplate property of the legend to the desired color.


Here 's an example:

<chart:SfCartesianChart.Resources>

      <ResourceDictionary>

        <converter:BrushToColorConverter x:Key="brushToColor" />

          <DataTemplate x:Key="legendTemplate">

                <Grid ColumnDefinitions="Auto,Auto" ColumnSpacing="5" Margin="5">

                   <BoxView Grid.Column="0"

                                      Color="{Binding IconBrush,Converter={StaticResource brushToColor}}"/>

                     <Label Grid.Column="1"

                                  Text="{Binding Item.Label}"

                                  TextColor="{Binding IconBrush,Converter={StaticResource brushToColor}}"/>

                   </Grid>

               </DataTemplate>

           </ResourceDictionary>

 </chart:SfCartesianChart.Resources>

 

 

<chart:SfCartesianChart.Legend>

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

</chart:SfCartesianChart.Legend>

 

       <chart:SplineSeries Label="Mobile"

                                          ItemsSource="{Binding Data}"

                                          XBindingPath="Year"

                                          YBindingPath="Mobile">

           </chart:SplineSeries>

 

            <chart:SplineSeries Label="Labtop"

                                                ItemsSource="{Binding Data}"

                                                XBindingPath="Year"

                                                YBindingPath="LapTop">

            </chart:SplineSeries>




In below attached the sample for reference. I hope this helps!


Regards,

Sowndharya Selladurai.



Attachment: LegendTextColor_e1d4db2a.zip


EK Eigil Krogh Sørensen April 3, 2023 05:44 PM UTC

Thank you very much !!



--

Eigil


Loader.
Live Chat Icon For mobile
Up arrow icon