We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Need to combine multiple line series to single legend item

I want to combine multiple line series to single legend item which has same label name.

3 Replies

LA Lavanya Anaimuthu Syncfusion Team February 7, 2020 08:55 AM UTC

Hi Ranjithkumar caliaperoumal,  
  
Greetings from Syncfusion.  
  
Query 1: How to combine multiple line series to map under one legenditem?  
You can enable one legend item by setting VisibilityOnLegend as Visible for primary series and collapsed the VisibilityOnLegend for other series and binding the first series visibility to other IsSeriesVisible property as per in the below code snippet.  
  
Code Snippet [Xaml]:  
  
<syncfusion:SfChart.Legend>  
                <syncfusion:ChartLegend CheckBoxVisibility="Visible" ToggleSeriesVisibility="True"/>  
</syncfusion:SfChart.Legend>  
  
<syncfusion:LineSeries x:Name="series1" ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue" Label="Series1" VisibilityOnLegend="Visible" />  
                <syncfusion:LineSeries ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue1" Label="Series2" VisibilityOnLegend="Collapsed" IsSeriesVisible="{Binding ElementName=series1, Path=IsSeriesVisible}"/>  
                <syncfusion:LineSeries ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue2" Label="Series3" VisibilityOnLegend="Collapsed" IsSeriesVisible="{Binding ElementName=series1, Path=IsSeriesVisible}"/>  
  
And we have prepared a sample based on your requirement and download the sample from below link.  
  
  
Screenshot:  
   
Thanks, 
Lavanya A. 
 



ZL Zeljko Lazic March 15, 2021 07:57 PM UTC

If the line series are being created at runtime. How would you create the bindings in the viewmodel or codebehind?


YP Yuvaraj Palanisamy Syncfusion Team March 16, 2021 09:12 AM UTC

Hi Zeljko Lazic, 
 
We have created the series at run time and bind the series collection to the Series property of SfChart. Please find the code example below. 
 
CodeSnippet: 
 
<syncfusion:SfChart x:Name="chart" Series="{Binding Series}" > 
 

Also, we have attached the sample for your reference. Please find the sample from the below link.
 
 

Regards,
 
Yuvaraj. 


Loader.
Up arrow icon