Page 1 of 1

LegendBox Programmatically Select/Deselect Series

Posted: Mon May 20, 2019 2:04 pm
by giryhepai
Hi all,

Is there any way I can programmatically Select/Deselect a series in the LegendBox?

For example:
Series1 - Checked
Series2 - Checked
HiddenSeriesByDefault - Unchecked

Best regards,
giryhepai

Re: LegendBox Programmatically Select/Deselect Series

Posted: Tue May 21, 2019 8:12 am
by Arction_LasseP
Hello,

Currently there is no property such as LegendBoxes[0].series.checked. The only exception is CheckBoxStateChanged -event, which has e.IsChecked -property, which tells the state of the clicked checkbox. This event, when subscribed to, triggers only when a checkbox in a legend box is clicked so it probably is not very useful in this case.

However, since having a series checked in the legend box basically means that the respective series should be visible in the chart, this kind of behaviour can be achieved by setting visibility of the series true/false. If freeformPointLineSeries.Visible is set true, the respective checkbox in the legend box should automatically be checked. Similarly, Visible = false means that the checkbox is not checked. Here is a simple example, in which all FreeformPointLineSeries are set not visible (unchecked in legend box) when a chart is double-clicked:

Code: Select all

_chart.MouseDoubleClick += _chart_MouseDoubleClick;

private void _chart_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            foreach (FreeformPointLineSeries fp in _chart.ViewXY.FreeformPointLineSeries)
            {
                fp.Visible = false;
            }           
        }
This behaviour is not limited to FreeformPointLineSeries only, as all the other series work the same way as well.

Hope this is helpful.

Re: LegendBox Programmatically Select/Deselect Series

Posted: Tue May 21, 2019 2:47 pm
by giryhepai
I like the idea you're presenting, although it doesn't actually help me.

Thanks for the suggestions,
giryhepai

Re: LegendBox Programmatically Select/Deselect Series

Posted: Fri May 24, 2019 2:09 pm
by ArctionKestutis
Actually Series.Visible property and LegendBox checkbox are tightly bind.
If you disable Series.Visible property it will clear corresponding item checkbox. And if you click the checkbox in Legend, this will modifies Series.Visible property.
I believe this is that you need.

Hope this helps.