简体   繁体   中英

Display two sets of data points on chart control?

I'm trying to use a chart control to show the difference between two separate items in a line chart.

Each item has a two dimensional array like the below:

double[,] a = { {1, 2}, {4, 5} };

How can I add each of these arrays as a separate series on a Chart control?

Thanks to the documentation that Ahmed gave me I managed to figure it out.

I'm writing how I managed to get it working in case anyone like me can't wrap their head around the chart controls. They were a bit confusing to me.

The simplest route I took to populate my chart with two separate series of data was this:

// 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM