Reputation: 49
I have a problem with a line chart. I have data which is not continuous, since values are measured only when the program is working.
I want to draw a line only when values are closer than one hour, in that I don't want any line (break in chart).
Code is as below:
chart1.Series[dataTable.Columns[x].Caption].ChartType =
System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
chart1.Series[dataTable.Columns[x].Caption].Points.AddXY(dataTable.Rows[i][0], dataTable.Rows[i][x]);
next
Upvotes: 0
Views: 1162
Reputation: 1670
Will allow you to plot points that wont plot a point on the line
chart1.Series[dataTable.Columns[x].Caption].Points.Add(new DataPoint(dataTable.Rows[i][0], double.NaN) { IsEmpty = true });
if you don't want to plot values less than an hour try an if statement in your for loop that will control the points plotted
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
//assuming dataTable.Rows[i][0] is time, then if the the value is in the
//last hour [DateTime.Now.AddHours(-1)] the if statement will allow the
//point to be plotted, otherwise it wont plot
if (dataTable.Rows[i][0] > DateTime.Now.AddHours(-1)) {
chart1.Series[dataTable.Columns[x].Caption].Points.AddXY(dataTable.Rows[i][0], dataTable.Rows[i][x]);
}
next
Upvotes: 1