Articles in this section
Category / Section

How to collapse the series through legend in .NET MAUI Chart (SfCartesianChart)?

3 mins read

This article describes the method to dynamically collapse a series by tapping the respective legend item in the .NET MAUI Charts.

This functionality enables isolating a required series from others, which is achieved using the ToggleSeriesVisibility property of the ChartLegend.


Example chart for collapsing the series through legend in .NET MAUI (SfCartesianChart)


Step 1: Initialize the Cartesian chart using the provided guideline.

Step 2The visibility of the series can be changed dynamically by setting the ToggleSeriesVisibility property of the ChartLegend to true.

 

[XAML]

<chart:SfCartesianChart>
        . . .
        <chart:SfCartesianChart.Legend>
            <chart:ChartLegend ToggleSeriesVisibility="True"/>
        </chart:SfCartesianChart.Legend>
        . . .
        <chart:SfCartesianChart.Series>
            <chart:ColumnSeries Label="ProductA" ItemsSource="{Binding CategoryData1}" XBindingPath="XValue" YBindingPath="YValue"/>
            <chart:ColumnSeries Label="ProductB" ItemsSource="{Binding CategoryData2}" XBindingPath="XValue" YBindingPath="YValue"/>
        </chart:SfCartesianChart.Series>
</chart:SfCartesianChart>

[C#]

SfCartesianChart chart = new SfCartesianChart();
chart.Legend = new ChartLegend()
{
     ToggleSeriesVisibility= true,
};
. . .
ColumnSeries series1 = new ColumnSeries();
chart.Series.Add(series1);
series1.ItemsSource = (new ViewModel()).CategoryData1;
series1.XBindingPath = "XValue";
series1.YBindingPath = "YValue";
series1.Label = "ProductA";
ColumnSeries series2 = new ColumnSeries();
chart.Series.Add(series2);
series2.ItemsSource = (new ViewModel()).CategoryData2;
series2.XBindingPath = "XValue";
series2.YBindingPath = "YValue";
series2.Label = "ProductB";
Content = chart;

 

Conclusion

I hope you enjoyed learning how to collapse series through legend in the .NET MAUI Chart.

Refer to the .NET MAUI Chart feature tour page to learn about its groundbreaking feature representations. You can also explore .NET MAUI Chart documentation to understand how to present and manipulate data. 

For current customers, check out Syncfusion® .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try the 30-day free trial to check out its .NET MAUI Chart and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. Contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied