【问题标题】:.NET Real Time Data Chart.NET 实时数据图表
【发布时间】:2016-07-22 20:36:54
【问题描述】:

我想在 asp.net 或 winForms 中制作一个显示过去 10 分钟的实时数据图表。

This is the image that i want to make it

我添加了系列,但无法添加数据点。我搜索了很多,但我失败了。

顺便说一句,我使用基础设施。

以下代码生成随机数并在图表中显示该数字。它有效,但只是最后一个数字,i can see it. 没有持续 10 分钟。

    private void Form1_Load(object sender, EventArgs e)
    { 
        Timer timer = new Timer();
        timer.Interval = (1 * 1000); // 1 secs
        timer.Tick += new EventHandler(timer_Tick);
        timer.Start();
    }

    private void timer_Tick(object sender, EventArgs e)
    {
        Random r = new Random();
        int rnd=r.Next(1, 150);
        DataTable dt = new DataTable();

        dt.Columns.Add("Value", typeof(int));
        dt.Columns.Add("Date", typeof(DateTime));
        dt.Rows.Add(rnd, DateTime.ParseExact(DateTime.Now.ToLongTimeString(), "HH:mm:ss", null));

        NumericTimeSeries series = new NumericTimeSeries();      
        series.DataBind(dt, "Date", "Value");
        NumericTimeDataPoint ndp1 = new NumericTimeDataPoint(DateTime.Now, rnd, "ilk", false);
        NumericTimeDataPoint ndp2 = new NumericTimeDataPoint(DateTime.Now, 5.0, "iki", false);
        series.Points.Add(ndp1);
        series.Points.Add(ndp2);
        ultraChart2.Data.SwapRowsAndColumns = true;
        ultraChart2.DataSource = dt;
    }

【问题讨论】:

    标签: c# asp.net .net winforms infragistics


    【解决方案1】:

    如果我正确理解您的问题,

    在每个刻度上,您都在替换您的数据,而不是添加到其中。

    尝试在 Form1_Load 处理程序中初始化系列一次,并在每次滴答时为其添加新值,而无需创建新的 DataTable,将其重新绑定到系列等等。


    为了清楚起见,

    您的 timer_Tick 处理程序应该只有 4 行代码:

    private void timer_Tick(object sender, EventArgs e)
    {
        NumericTimeDataPoint ndp1 = new NumericTimeDataPoint(DateTime.Now, rnd, "ilk", false);
        NumericTimeDataPoint ndp2 = new NumericTimeDataPoint(DateTime.Now, 5.0, "iki", false);
        _series.Points.Add(ndp1);
        _series.Points.Add(ndp2);
    }
    

    将 _series 声明为私有成员,从 Form1_Load 处理程序中对其进行初始化,然后就可以开始了。

    【讨论】:

    • 我做了一些更改,但它会引发错误。你会编辑pastebin吗,那对我来说太棒了。 pastebin.com/vqDsNUv1
    • 我猜,并说问题在于您在负载处理程序中声明 NumericTimeSeries _series = new NumericTimeSeries();。把它放在外面,作为私人成员。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-26
    • 2013-01-17
    相关资源
    最近更新 更多