SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Hi,
I have a surface with multiple dataseries in it. I have a legend for each serie, setup like this:
chart.ChartModifier = new Abt.Controls.SciChart.ChartModifiers.LegendModifier() { Name = "legendModifier" }; var legend = new Abt.Controls.SciChart.Visuals.SciChartLegend { Margin = new Thickness(5) }; // Bind the legend to the data source var legendDataBinding = new Binding("LegendData") { Source = chart.ChartModifier }; legend.SetBinding(Abt.Controls.SciChart.Visuals.SciChartLegend.LegendDataProperty, legendDataBinding);
And it works fine.
However, I would also like to bind the visibility of the legends to the visibility of the dataseries. I have tried this:
// Bind the legend visibility to the data source var legendVisibilityBinding = new Binding("Visibility") { Converter = new BoolToVisibilityConverter(), Source = line.IsVisible }; legend.SetBinding(Abt.Controls.SciChart.Visuals.SciChartLegend.LegendDataProperty, legendVisibilityBinding);
But it doesn’t seem to work, any suggestions, anyone?
BR
Jacob
Hi Jacob, I believe you’re incorrectly binding the LegendDataProperty to a boolean with BoolToVisibilityConverter. Shouldn’t it be the Visibility property?
chart.ChartModifier = new Abt.Controls.SciChart.ChartModifiers.LegendModifier() { Name = "legendModifier" }; var legend = new Abt.Controls.SciChart.Visuals.SciChartLegend { Margin = new Thickness(5) }; // Bind the legend to the data source
var legendDataBinding = new Binding("LegendData") { Source = chart.ChartModifier };
legend.SetBinding(Abt.Controls.SciChart.Visuals.SciChartLegend.LegendDataProperty, legendDataBinding); legend.BorderThickness = new Thickness(0);// no border in the legend
legend.ShowVisibilityCheckboxes = false;//no checkboxes legend.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);// Disable the vertical scrollbar
grid.Children.Add(legend);// Add legend to the view
In the chart, which is also a child in the same grid that the legend is in, I have added several renderable series and it looks fine; there is a legend-label for each series. So my question is how to collapse/hide the individual legends, optimally as a binding to the individual series IsVisible property? BR
JacobHi Andrew,
Yes, I think you are right, it should be visibility property, it didn’t make it work though. Actually, the problem has evolved a bit since I actually have several renderable series in one chart.
As mentioned in the earlier post, I create a single SciChartLegend and bind the LegendData to the chartModifier. This makes a legend for every series in the chart. So how can this be made to switch on/off legends individually when a series is made invisible?
BR
Jacob
Please login first to submit.