我正在尝试使用图表控件来显示折线图中两个单独项目之间的差异。
每个项目都有一个二维数组,如下所示:
double[,] a = { {1, 2}, {4, 5} };
如何将这些数组中的每一个添加为Chart控件上的单独系列?
答案 0 :(得分:1)
答案 1 :(得分:0)
感谢艾哈迈德给我的文件,我设法弄明白了。
我正在写我如何设法让它工作以防万一像我这样的人不能围绕图表控件。他们对我来说有点混乱。
我用两个独立的数据系列填充图表的最简单路线是:
// 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