# chart-cartesian-legend-toggle

> ColumnSeries fruit sales chart with toggleable ChartLegend, animation, tooltips, and a CategoryAxis.

**Framework:** winui  **Component:** Chart  **Variant:** cartesian-legend-toggle

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/winui/chart-cartesian-legend-toggle.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.Chart.WinUI
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/chart-cartesian-legend-toggle/Chart.xaml

```xaml
﻿<Page
    x:Class="Chart.Samples.CartesianLegendToggle.Chart"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:chart="using:Syncfusion.UI.Xaml.Charts"
    xmlns:local="using:Chart">

    <Grid x:Name="grid">
        <Grid.DataContext>
            <local:LegendViewModel />
        </Grid.DataContext>
        <chart:SfCartesianChart
            x:Name="chart"
            Height="420"
            HorizontalAlignment="Center"
            Header="Comparison of Fruit Sales in a Shop">

            <chart:SfCartesianChart.Resources>
                <ResourceDictionary>
                    <SolidColorBrush x:Key="SeriesBrush3" Color="#FFC107"/>
                    <SolidColorBrush x:Key="SeriesBrush5" Color="#4CAF50"/>
                    <SolidColorBrush x:Key="SeriesBrush6" Color="#E91E63"/>
                    <SolidColorBrush x:Key="SeriesBrush7" Color="#FF9800"/>
                    <Style TargetType="Line" x:Key="axisStyle">
                        <Setter Property="StrokeThickness" Value="0"/>
                        <Setter Property="Stroke" Value="Transparent"/>
                    </Style>
                </ResourceDictionary>
            </chart:SfCartesianChart.Resources>

            <chart:SfCartesianChart.XAxes>
                <chart:CategoryAxis Interval="2" ShowMajorGridLines="False" EdgeLabelsDrawingMode="Shift" />
            </chart:SfCartesianChart.XAxes>

            <chart:SfCartesianChart.YAxes>
                <chart:NumericalAxis
                    Maximum="1" AxisLineStyle="{StaticResource axisStyle}" MajorTickStyle="{StaticResource axisStyle}"
                    Minimum="0"
                    Interval="1">
                    <chart:NumericalAxis.LabelStyle>
                        <chart:LabelStyle LabelFormat="0'B"  FontSize="12.5"/>
                    </chart:NumericalAxis.LabelStyle>
                </chart:NumericalAxis>
            </chart:SfCartesianChart.YAxes>

            <chart:SfCartesianChart.Legend>
                <chart:ChartLegend IconHeight="13" IconWidth="13" ToggleSeriesVisibility="True" Padding="0,0,25,0"/>
            </chart:SfCartesianChart.Legend>

            <chart:ColumnSeries
                Fill="{StaticResource SeriesBrush3}"
                EnableAnimation="True"
                ItemsSource="{Binding ToggledLegendData}"
                Label="Apple"
                EnableTooltip="True"
                XBindingPath="Name"
                YBindingPath="Apple"
                LegendIcon="Circle"/>

            <chart:ColumnSeries
                Fill="{StaticResource SeriesBrush5}"
                EnableAnimation="True"
                ItemsSource="{Binding ToggledLegendData}"
                Label="Orange"
                EnableTooltip="True"
                XBindingPath="Name"
                YBindingPath="Orange"
                LegendIcon="Circle"/>

            <chart:ColumnSeries
                Fill="{StaticResource SeriesBrush7}"
                EnableAnimation="True"
                ItemsSource="{Binding ToggledLegendData}"
                Label="Pear"
                EnableTooltip="True"
                XBindingPath="Name"
                YBindingPath="Pear"
                LegendIcon="Circle"/>

            <chart:ColumnSeries
                Fill="{StaticResource SeriesBrush6}"
                EnableAnimation="True"
                ItemsSource="{Binding ToggledLegendData}"
                Label="Others"
                EnableTooltip="True"
                XBindingPath="Name"
                YBindingPath="Others"
                LegendIcon="Circle"/>

            <chart:SfCartesianChart.SelectionBehavior>
                <chart:SeriesSelectionBehavior SelectionBrush="Red"/>
            </chart:SfCartesianChart.SelectionBehavior>

        </chart:SfCartesianChart>
    </Grid>
</Page>
```
