[英]Display two sets of data points on chart control?
我正在尝试使用图表控件来显示折线图中两个单独项目之间的差异。
每个项目都有一个二维数组,如下所示:
double[,] a = { {1, 2}, {4, 5} };
如何将每个数组添加为Chart控件上的单独序列?
多亏了艾哈迈德(Ahmed)给我的文档,我才得以弄清楚。
我正在写我如何设法使它工作,以防像我这样的人无法将头放在图表控件周围。 他们让我有些困惑。
我使用两个单独的系列数据填充图表的最简单方法是:
// set chart
Chart compareChart = dropoffChartForm.dropoffDamageChart;
// set chart basics
compareChart.Series.Clear(); // clear existing series
compareChart.ChartAreas[0].AxisX.Interval = 10.0; // interval of striplines
compareChart.ChartAreas[0].AxisX.Minimum = 0; // minimum of X axis
compareChart.ChartAreas[0].AxisX.Maximum = 100; // maximum of X axis
compareChart.ChartAreas[0].AxisX.Title = "Meters"; // title of X axis
compareChart.ChartAreas[0].AxisY.Title = "Damage per Bullet"; // title of Y axis
// add A series
compareChart.Series.Add(A.name);
compareChart.Series[A.name].Points.DataBindXY(A.pointsX, A.pointsY);
compareChart.Series[A.name].ChartType = SeriesChartType.Line; // set type to line chart
compareChart.Series[A.name].Color = Color.Red;
// only add B series if it differs from A series
if (A.name != B.name) {
compareChart.Series.Add(B.name);
compareChart.Series[B.name].Points.DataBindXY(B.pointsX, B.pointsY); // each of these is a simple array of 4 doubles
compareChart.Series[B.name].ChartType = SeriesChartType.Line; // set type to line chart
compareChart.Series[B.name].Color = Color.Blue;
}
compareChart.Update(); // update chart after adding data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.