Hidden series initially shows as visibel on legend

While adding series to a chart, through code, we set some of the series as hidden (Hidden or Collapsed). When the chart shows, the series we want hidden are hidden, which is good. But on the legend, all series are shown as if they're visible. To show a series that was originally set to be hidden, the user has to click its legend twice (first click makes the legend semitransparent, second click makes it opaque and shows the series). How can we make the legend items respect the original visibility of their series?





5 Replies

DD Devakumar Dhanapoosanam Syncfusion Team April 20, 2020 05:03 PM UTC

Hi Marcus Johansson, 
 
Greetings from Syncfusion. 
 
We have analyzed your query and we would like to let you know that the you can control the Legend item visibility for particular series using the VisibilityOnLegend property in series. You can achieve your requirement by binding a same property for the series Visibility and IsVisibleOnLegend property based on your requirement.  
 
Please refer the help document for more details, 
 
 
Please let us know whether the above solution helps to achieve your requirement or not. If not, please share more details of your requirement which will be for us analyze and provide a better solution earlier.  
 
If you need any further assistance, please don't hesitate to contact us. 
 
Regards, 
Devakumar D 



MJ Marcus johansson April 21, 2020 07:18 AM UTC

Sadly, this doesn't solve the problem.

We want the item to be visible on the legend even if the series is hidden from start. The user would then click on the legend item to show the hidden series. The problem is that the legend item is opaque (instead of semi-tranparent) from start even if the series is hidden. The initial STATE of the legend item doesn't match the series visibility.

If we set IsVisibleOnLegend to Hidden, the legend item wouldn't be visible at all, which means there would be no way for the user to show the hidden series.




DD Devakumar Dhanapoosanam Syncfusion Team April 22, 2020 07:32 PM UTC

Hi Marcus Johansson, 
 
Thanks for the update.  
 
We would like to let you know that you can achieve your requirement by setting the Series IsSeriesVisible property as false for the hidden/collapsed series to show the legend item as semitransparent based on your requirement. 
 
Also, we have prepared a workaround for dynamic changes of the series visibility by extending the chart Series as in the below code snippet,  
  
C#:  
public class LineSeriesExt : LineSeries  
 
      protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)  
      {  
            base.OnPropertyChanged(e);  
              
            if (e.Property.Name == nameof(this.Visibility))  
            {  
                var legend = (Area.Legend as ChartLegend);  
                foreach (LegendItem item in legend.Items)  
                {  
                    if (item.Series == this 
                    {  
                        item.IsSeriesVisible = this.Visibility == Visibility.Visible;  
                        break 
                    }  
                }  
            }  
      }  
 
 
  
XAML:  
<syncfusion:SfChart x:Name="chart">  
       …  
       <syncfusion:SfChart.Legend>  
                <syncfusion:ChartLegend x:Name="legend" ToggleSeriesVisibility="True" >  
                syncfusion:ChartLegend>  
       syncfusion:SfChart.Legend>  
  
       <local:LineSeriesExt x:Name="series1" ItemsSource="{Binding Data}"   
                                   XBindingPath="XValue" YBindingPath="YValue" Label="Series 1"/>  
      ….  
syncfusion:SfChart>  
 
  
  
Please let us know if you need any further assistance on this. 
 
Regards, 
Devakumar D 



MJ Marcus johansson April 23, 2020 06:40 AM UTC

Thank you for the answer!

We were using the Visibility property instead of IsSeriesVisible. Now it works perfectly!

/Marcus


DD Devakumar Dhanapoosanam Syncfusion Team April 24, 2020 06:00 AM UTC

Hi Marcus Johansson, 
 
Thanks for the update. 
 
We are glad to hear that the provided solution works for your requirement. 
 
Please let us know if you need any further assistance. 
 
Regards, 
Devakumar D 


Loader.
Up arrow icon