簡體   English   中英

在圖表控件上顯示兩組數據點?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM