Pre loader

Legend-data series visibility binding

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

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 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 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 Burnett-Thompson
    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.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies