如何使用一个具有多个ChartAreas的系列?

时间:2016-10-19 19:19:54

标签: c# charts series

我有一个Chart,其中有三个ChartArea。第一个图表区域chartarea1绘制来自series1chartarea2series2的数据。但我希望chartarea3能够制作series1series2。我的所有搜索都返回了在Series上绘制多个ChartArea的方式,而我没有遇到问题,我想要做的是在多个{Series上绘制ChartArea 1}}秒。有没有办法做到这一点? Series["item"].ChartArea属性仅设置一个ChartArea

这是我的尝试,我尝试创建series3series4并分别为series1series2分配,但它不起作用(我怀疑是因为它们是引用类型,它实际上并没有克隆series1series2,我觉得我将不得不这样做。

ChartArea chartarea1 = new ChartArea();
chartarea1.Name = "chartarea1";
chart1.ChartAreas.Add(chartarea1);

Series series1 = new Series();
series1.Name = "series1";
series1.ChartType = SeriesChartType.Line;
chart1.Series.Add(series1);
chart1.Series["series1"].ChartArea = "chartarea1";

chart1.Series["series1"].Points.DataBindY(someArray1);

ChartArea chartarea2 = new ChartArea();
chartarea2.Name = "chartarea2";
chart1.ChartAreas.Add(chartarea2);

Series series2 = new Series();
series2.Name = "series2";
series2.ChartType = SeriesChartType.Line;
chart1.Series.Add(series2);
chart1.Series["series2"].ChartArea = "chartarea2";

chart1.Series["series2"].Points.DataBindY(someArray2);

ChartArea chartarea3 = new ChartArea();
chartarea3.Name = "chartarea3";
chart1.ChartAreas.Add(chartarea3);

Series series3 = series1;
Series series4 = series2;
series3.Name = "series3";
series4.Name = "series4";
chart1.Series["series3"].ChartArea = "chartarea3";
chart1.Series["series4"].ChartArea = "chartarea3";

chart1.Invalidate();

截至目前,当我排除涉及chartarea3series3series4的代码时,它会按照我的预期进行绘制:两个折线图,首先显示来自{{1的数据下面的第二个,显示来自someArray1的数据。但是,如果我包含其余代码,那么表单会显示一个大空格,someArray2chartarea1应该是chartarea2,然后是chartarea3sommeArray1sommeArray2绘制了。

提前致谢。

0 个答案:

没有答案