Articles in this section
Category / Section

How to Deselect Segments Programmatically in UWP SfChart?

This article demonstrates how to programmatically deselect chart segments or series in the UWP Chart control from the code behind.

Step 1: Configure the SfChart and set up the ChartSelectionBehavior

SfChart chart = new SfChart();

chart.PrimaryAxis = new CategoryAxis();
chart.SecondaryAxis = new NumericalAxis();

chart.Behaviors.Add(new ChartSelectionBehavior { EnableSeriesSelection = true });

ColumnSeries series1 = new ColumnSeries
{
    ItemsSource = viewModel.DataSource,
    XBindingPath = "XValue",
    YBindingPath = "YValue",
    SegmentSelectionBrush = new SolidColorBrush(Colors.Gold)
};

ColumnSeries series2 = new ColumnSeries
{
    ItemsSource = viewModel.DataSource2,
    XBindingPath = "XValue",
    YBindingPath = "YValue",
    SeriesSelectionBrush = new SolidColorBrush(Colors.Silver)
};

chart.Series.Add(series);
chart.Series.Add(series2);

Content = chart;

 
Step 2: To deselect a specific chart segment from code behind, set the SelectedIndex property of the ChartSeries to -1. 

series1.SelectedIndex = -1;
Step 3: To deselect a specific series from code behind, set the SeriesSelectedIndex property of the Chart to -1.
chart.SeriesSelectedIndex = -1;

Conclusion

I hope you enjoyed learning about how to deselect the chart segment by using code behind in UWP Chart.

You can refer to our UWP Chart feature tour page to know about its other groundbreaking feature representations. You can also explore our UWP Chart documentation to understand how to create and manipulate data.

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

If you have any queries or require clarifications, please let us know in the comments section below. You can also 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)
Access denied
Access denied