add stripline to legend

Is it possible to add the stripline color/name to a legend on an SfChart?

Thanks

1 Reply

MK Muneesh Kumar G Syncfusion Team April 5, 2018 07:06 AM UTC

 
Thanks for using Syncfusion products.  
 
We have analyzed your requirement, currently we don’t have direct support for add stripline in legend. But we have achieved your requirement by adding stripline to legend items collection manually as follows.  
 
Code snippet [C#]: 
ChartLegend legend = new ChartLegend(); 
 
            foreach (var series in chart.Series) 
            { 
                legend.Items.Add(new LegendItem() 
                { 
                    Label = series.Label, 
                    Series = series, 
                    IconHeight = 10, 
                    IconWidth = 10, 
                    IconVisibility = Visibility.Visible 
                }); 
            } 
 
            foreach (var line in chart.PrimaryAxis.StripLines) 
            { 
                legend.Items.Add(new LegendItem() 
                { 
                    Label = line.Name, 
                    IconHeight = 10, 
                    IconWidth = 10, 
                    LegendIconTemplate=grid.Resources["stripline"] as DataTemplate, 
                    IconVisibility = Visibility.Visible 
                }); 
            } 
 
            chart.Legend = legend; 
 
 
Code snippet [XAML]: 
<Grid.Resources> 
    <DataTemplate x:Key="stripline"> 
         <Canvas> 
            <Rectangle Height="10" Width="10" Fill="Yellow"/> 
         </Canvas> 
    </DataTemplate> 
</Grid.Resources> 
 
We have prepared a sample based on this, please find the sample from the following location.  
 
 
Please let us know if you have any queries.  
 
Thanks, 
Muneesh Kumar G. 
 


Loader.
Up arrow icon