C#图表不连续 [英] c# chart non continuous

查看:112
本文介绍了C#图表不连续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对折线图有疑问.我有不连续的数据,因为仅在程序运行时才测量值.

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).

代码如下:

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

推荐答案

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

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

这篇关于C#图表不连续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆