Skip to content

This example demonstrates the customization of individual legend item based on a condition in Xamarin.Forms chart.

Notifications You must be signed in to change notification settings

SyncfusionExamples/how-to-customize-the-individual-legend-item-based-on-a-condition-in-xamarin-forms-sfchart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

How to customize the individual legend item based on a condition in Xamarin.Forms Chart (SfChart)?

This example demonstrates the customization of individual legend item based on a condition in Xamarin.Forms chart.

You can customize all the legend items by setting individual style using the LegendItemCreated event. This event will be fired when a chart legend item is created. For more details about the event arguments, refer to this documentation.

The following code sample demonstrates how to set individual style to all the legend items.

XAML

<chart:SfChart x:Name="chart" LegendItemCreated="Chart_LegendItemCreated">

C#

chart.LegendItemCreated += Chart_LegendItemCreated;
 
private void Chart_LegendItemCreated(object sender, ChartLegendItemCreatedEventArgs e)
{
   Model model = e.LegendItem.DataPoint as Model;
   e.LegendItem.Label = model.XValue + ": " + model.YValue.ToString();
   e.LegendItem.LabelStyle = new ChartLegendLabelStyle()
   {
        TextColor = model.YValue > 50 ? Color.Green : Color.Red,
        FontFamily = model.YValue > 50 ? "Times New Roman" : "Arial"
    };
}

Output:

Pie Chart with customized legend items in Xamarin.Forms

KB article - How to customize the individual legend item based on a condition in Xamarin.Forms Chart?

Requirements to run the demo

Troubleshooting

Path too long exception

If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

About

This example demonstrates the customization of individual legend item based on a condition in Xamarin.Forms chart.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages