Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Hide/Show data series with XamChart
posted

Hi,

Is there a way to hide/show data series on a WPF XamChart?

The best would be a checkbox for each series on the Legend. I can do that with a LegendItemTemplate, but how can I connect the checkbox to a series (could hide it by setting the Fill to transparent)?

Thanks in advance,

Szilveszter

Parents
No Data
Reply
  • 9836
    posted

    Hi Szilvester,

    There are two ways to show/hide the series in the XamChart :

    1. Setting the Fill property of each Series to Transparent (also the StrokeThickness to 0 so you can remove the outer border) .

    2. Manually add/remove the Series objects from the XamChart.Series collection.

    Regarding the first option If you use a checkboxes outside the chart you can easily bind the Fill property of the Series to the IsChecked property of the checkbox using converter. The binding is possible because the elements are in the VisualTree so you can use ElementName in the binding syntax e.g.

    <Series1"  StrokeThickness="0" Fill="{Binding ElementName=check1,Path=IsChecked,Converter={StaticResource customConverter}, ConverterParameter=Green}">

    However in your case the checkboxes are in a DataTemplate so your best option is to handle the Checked/Unchecked events, get the Series and set the Fill property in codebehind. Please note that when the Fill property changes the XamChart updates the layout which can probably retrieve the current status of the checkboxes and cause some issues. You can take a look at my sample project showing the both scenarios.

    Let me know if you have any questions with this matter.

    Vlad

    WpfApplication5.zip
Children