Reputation:
I want to make a real time data chart that shows last 10 minutes in asp.net or winForms.
This is the image that i want to make it
I added the series but could not add datapoints. I searched a lot but i failed.
I use infragistics by the way.
Below code generates random numbers and shows that number in the charts. It works but just last number that i can see it. not last 10 minutes.
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;
}
Upvotes: 0
Views: 930
Reputation: 692
If I understand your problem correctly,
On each tick, you are replacing your data instead of adding to it.
Try initializing the series once in the Form1_Load handler, and on each tick, just add new values to it, without creating a new DataTable, rebinding it to the series and so on.
To make things clear,
Your timer_Tick handler should have only 4 lines of code:
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);
}
Declare the _series as a private member, initialize it from the Form1_Load handler, and you should be good to go.
Upvotes: 1