vb.net 如何在图表中设置系列 Z 顺序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23964428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:38:28  来源:igfitidea点击:

How to set series Z-Order in Chart

c#vb.netchartsmschart

提问by Jens

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.

我有一个带有多个系列的图表控件(System.Windows.Form.DataVisualisation.Charting,所以 WinForms),一些分配给主要的,一些分配给次要的 Y 轴。

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.

我需要图表以特定的 Z 顺序绘制系列(意味着首先绘制哪个系列,第二个,依此类推),因为其中一些是重叠的。我找不到任何相关的财产。

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.

我认为 z 顺序将取决于将系列添加到 SeriesCollection 的顺序,但这在我的测试中似乎没有任何改变。

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.

PS:这不是 3D-Graph。所以我只询问绘制不同系列的顺序。

回答by Ben

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 Insertinstead of an Add:

系列是按照它们放入 Chart.Series 集合的顺序绘制的。因此,您可以使用 anInsert而不是 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.

以下可以转换为图表控件的扩展方法,然后(与其他方法一起,例如Br​​ingToFront)可以用于设置系列的顺序。

public void SendToBack(Series s)
{
    if (myChart1.Series.Contains(s))
    {
        myChart1.Series.Remove(s);
        myChart1.Series.Insert(0, s);
    }
}

回答by mmathis

The series are drawn in the order in which they are added to the Chart.Seriescollection. Add the one you want drawn on top as the last element in the collection.

系列按照它们添加到Chart.Series集合中的顺序绘制。添加您想在顶部绘制的元素作为集合中的最后一个元素。