https://github.com/syncfusionexamples/how-to-control-the-visibility-of-all-series-with-a-single-legend-item-in-cartesian-chart
This article in the Syncfusion Knowledge Base explains how to control the visibility of all series with a single legend item in Cartesian chart
https://github.com/syncfusionexamples/how-to-control-the-visibility-of-all-series-with-a-single-legend-item-in-cartesian-chart
chart-legend charting-library charts column-series control-series-visibility data-visualization interactive-charts is-visible-on-legend maui-charts toggle-series-visibility
Last synced: about 2 months ago
JSON representation
This article in the Syncfusion Knowledge Base explains how to control the visibility of all series with a single legend item in Cartesian chart
- Host: GitHub
- URL: https://github.com/syncfusionexamples/how-to-control-the-visibility-of-all-series-with-a-single-legend-item-in-cartesian-chart
- Owner: SyncfusionExamples
- Created: 2024-04-26T11:23:18.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-14T05:34:12.000Z (about 1 year ago)
- Last Synced: 2025-02-08T20:47:55.513Z (3 months ago)
- Topics: chart-legend, charting-library, charts, column-series, control-series-visibility, data-visualization, interactive-charts, is-visible-on-legend, maui-charts, toggle-series-visibility
- Language: C#
- Homepage:
- Size: 215 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# How-to-control-the-visibility-of-all-series-with-a-single-legend-item-in-Cartesian-chart
This article will explain the step to control the visibility of all series with a single legend item in a [Cartesian chart](https://www.syncfusion.com/maui-controls/maui-cartesian-charts).
**Step 1:** Initialize the [ChartLegend](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartLegend.html) and set the [ToggleSeriesVisibility](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartLegend.html#Syncfusion_Maui_Charts_ChartLegend_ToggleSeriesVisibility) as true to control the series visibility.**[XAML]**
```
```
**Step 2:** Enable the legend for the first series by setting the [IsVisibleOnLegend](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_IsVisibleOnLegend) to `"True"` and `"False"` for the remaining series.**[XAML]**
```. . .
```
**Step 3:** Control the series visibility by using the following solutions:**Solution 1 :**
Binding the [IsVisible](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_IsVisible) property of first series, to the rest of the series as shown in the following code sample.**[XAML]**
```. . .
```
**Solution 2 :**
Without binding, you can also control all the series visibility by binding the same Boolean property (the property that holds the state of series visibility) from the view model to all the associated series [IsVisible](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_IsVisible) property. In this way, when the primary series legend is clicked, all the associated series visibility also collapsed. The following code sample shows how to toggle multiple series with a single legend item.**[XAML]**
```. . .
```
**[C#]**
```
public class ViewModel : INotifyPropertyChanged
{
. . .
private bool isSeriesVisible = true;public event PropertyChangedEventHandler PropertyChanged;
public bool IsSeriesVisible
{
get { return isSeriesVisible; }
set
{
isSeriesVisible = value;
OnPropertyChanged(nameof(IsSeriesVisible));
}
}protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
. . .
}
```
**Output**
