且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#图表不连续

更新时间:2023-02-07 23:42:35

将允许您绘制不会在线上绘制点的点

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 });

如果您不想绘制少于一小时的值,请尝试在for循环中使用if语句来控制绘制的点

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