How to set series Z-Order in Chart
c#, charts, mschart, vb.net
Solution
The series are drawn in the order they are placed into the Chart.Series collection. Therefore you can automatically send new series to the back by using an `Insert` instead of an `Add`:
myChart1.Series.Add(myNewSeries1); // Draws this series on top of the others.
myChart1.Series.Insert(0, myNewSeries2); // Draw this series behind the others.
The following could be converted to an extension method for the chart control and (along with other methods e.g. BringToFront) could then be used in setting the order of series.
public void SendToBack(Series s)
{
if (myChart1.Series.Contains(s))
{
myChart1.Series.Remove(s);
myChart1.Series.Insert(0, s);
}
}
Problem
I have a Chart Control (System.Windows.Form.DataVisualisation.Charting, so WinForms) with multiple series, some are assigned to the primary, and some to the secondary Y-axis. I need the chart to draw the series in a specific Z-order (meaning which series is drawn first, second, and so on), because some of them are overlapping. I can't find any related property. I thought the z-order would depend on the order in which the series are added to the SeriesCollection, but this doesn't seem to change anything in my tests. Am I missing something? PS: It's not a 3D-Graph. So I am only asking about the order in which the different series are drawn.