1

I need to create a website which present a number of charts (preferably line graphs) which will actively (in real time) display data as it is being read from a sensor. I have successfully created active live charts in Windows Forms Application, however they do not let display my data on an internet website.

Therefore I have attempted to create a simple graph in an ASP.NET Application using a Web Forms ASP.NET 4.5.2 template. The Default.aspx.cs code was simple and as I was trying to plot a point on a graph every 500 ms whenever button 1 is pressed. However when I opened the application in my browser pressing button 1 caused the timer to activate, but the graph remained blank (flickered on the screen). Please can somebody help me create a chart that can actively update to display new data as it is captured/generated.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : Page
    {
        int i = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            Timer1.Interval = 1000;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Timer1.Enabled = true;
        } 

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            this.Chart1.Series["Series1"].Points.AddXY(i, i);
            i++;
        }
    }
}
CDspace
  • 2,639
  • 18
  • 30
  • 36
Marco Soto
  • 61
  • 1
  • 11

2 Answers2

0

Checkout Signal - https://www.asp.net/signalr. Your code above uses webforms. Although it's doable but I prefer you use newer framework like MVC for your front-end/web.

alltej
  • 6,787
  • 10
  • 46
  • 87
0

Your server side approach won't work in this case: You need to use either:

to get your latest data for the chart. That means you need to change you web-form a bit to expose web service that will provide you latest data and update UI to consume this via javascript.

Community
  • 1
  • 1
klashar
  • 2,519
  • 2
  • 28
  • 38