This example demonstrates how you can provide each legend item with a check box, which controls the visibility of the corresponding series in the bound mode (obsolete approach).
Note that starting with the DXperience version 13.2.1, the chart control supports a built-in check box in the Legend feature. For more details, see the Legend Check Box topic.
To accomplish this, it is necessary to assign the Legend.Template property to custom template and then bind the ItemsSource property of the ItemsControl object to SeriesNonVisualWrappersCollection.
This custom collection is synchronized with the diagram's series collection when the SeriesCollection.CollectionChanged event fires.
In addition, the fake series source is created in the chart's data source to avoid hiding the legend when the Series.Visible property is set to false for all series.
See also:
- How to display custom information in the legend;
- How to display check boxes for legend items to control the visibility of series in the unbound mode
Question Comments
Added By: Aleksei Smirnov at: 4/28/2014 8:44:38 AM
Hello,
thanks for a very good example. It is really useful. However it is not working as expected. The color in the legend is not the same as the color in the chart in cases when visibility is changed.
The reason is that chart is uses palette only for visible elements. I mean if only one series is visible it would be always the same color independently on the series type. For example, if Series2 is the only visible series it is red. If Series1 is the only visible it is red too! When I make Series1 invisible, Series2 changes it's color from Green to Red. Legend still shows the original colors!
Could you please suggest the way how to disable such behavior? I don't want the series to change their colors if amount of visible series are changing.
Thanks
Added By: Eugene M (DevExpress) at: 4/28/2014 11:24:14 PMHello, Aleksei
Can you please clarify what version of DevExpress product you are using?
Hello Eugene,
I am using DevExpress 13.2_9
I'm happy to inform you that we have a built-in check box in the Legend feature starting from the 13.2.1 release. Please refer to the Legend Check Box topic.
Added By: Aleksei Smirnov at: 4/29/2014 6:54:10 AMThanks, Eugene. Good news!