SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

1
0

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

  • You must to post comments
0
0

Hi Jacob, I believe you’re incorrectly binding the LegendDataProperty to a boolean with BoolToVisibilityConverter. Shouldn’t it be the Visibility property?

  • JacobB
    Hi Andrew,Ok, I have moved my last answer here and also added some more code... .........................................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?My code for legend setup is as follows: 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 checkboxeslegend.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 Jacob
  • JacobB
    I snoozed around a little myself, and found that the answer to the problem:((Abt.Controls.SciChart.ChartModifiers.LegendModifier)chart.ChartModifier).GetLegendDataFor = Abt.Controls.SciChart.ChartModifiers.SourceMode.AllVisibleSeries;With this property set to AllVisibleSeries the legend for a series will be collapsed when the series IsVisible property is set to false...
  • You must to post comments
0
0

Hi 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

  • Andrew
    Hi Jacob, please move your answer to a comment on my answer. its just like stackoverflow! :) Can you update your question with extra code too to give us more info?
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.