buy now
log in

Q: How can I replace the standard legend that shows titles of the series in my chart with two legends at the two sides of the chart?

A: You have two ways to do this. One is to create to separate lists with ChartSeries – to be used as data for the two separate legends. Here is your code:

 var firstSeries = new ChartSeriesCollection() { series0, series1 };
 var secondSeries = new ChartSeriesCollection() { series2, series3 };
 ChartLegend legend1 = new ChartLegend();
 legend1.Series = firstSeries;
 LayoutPanel.SetDock(legend1, Dock.Right);

 ChartLegend legend2 = new ChartLegend();
 legend2.Series = secondSeries;
 LayoutPanel.SetDock(legend2, Dock.Left);

The second option is to create two SeriesLegend objects for which you set the labels and brushes to the titles and strokes of your series. Here is how you do it:

 SeriesLegend legend1 = new SeriesLegend();
 legend1.LabelsSource = new List(){series0.Title, series1.Title};
 legend1.BrushesSource = new List() { series0.Fills[0], series1.Fills[0] };
 LayoutPanel.SetDock(legend1, Dock.Right);

 SeriesLegend legend2 = new SeriesLegend();
 legend2.LabelsSource = new List() { series2.Title, series3.Title };
 legend2.BrushesSource = new List() { series2.Fills[0], series3.Fills[0] };
 LayoutPanel.SetDock(legend2, Dock.Left);

Here we assume the ChartSeries have their Title property set, and have at least one Brush added to their Fills list:

 LineSeries series1 = new LineSeries();
 series1.XData = new List() { 4, 7, 12, 16 };
 series1.YData = new List() { 45, 62, 18, 32 };
 series1.Title = "Tokyo";

Copyright © 2001-2019 MindFusion LLC. All rights reserved.
Terms of Use - Contact Us