Profile Picture

Add Past point to real time graph

Posted By Daniel Csimszi 11 Years Ago
Author
Message
Daniel Csimszi
Posted 11 Years Ago
View Quick Profile
Forum Guru

Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 61, Visits: 35
Hi,

I am just wondering if it is possible to add previous(in date time value) points to a real time graph without redrawing the whole graph. I send through data via network, so it is possible to have data which is arrives later but I still would like to add that point to the graph.

Regards
Daniel

Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 1 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Daniel,

Yes - you simply need to find to index at which to place the value - for example:

      private void Form1_Load(object sender, EventArgs e)
      {
         NChart chart = nChartControl1.Charts[0];
         chart.BoundsMode = BoundsMode.Stretch;

         NLineSeries line = new NLineSeries();
         line.UseXValues = true;
         chart.Series.Add(line);

         AddDataPoint(line, 1, 1);
         AddDataPoint(line, 3, 3);
         AddDataPoint(line, 2, 2);
      }

      private void AddDataPoint(NLineSeries line, double x, double y)
      {
         int i;

         for (i = line.XValues.Count - 1; i > 0; i--)
         {
            if ((double)line.XValues[i] < x)
            {
               break;
            }
         }

         if (i < 0)
         {
            i = 0;
         }
         line.XValues.Insert(i, x);
         line.Values.Insert(i, y);
      }

Hope this helps...

Best Regards,
Nevron Support Team



Daniel Csimszi
Posted 11 Years Ago
View Quick Profile
Forum Guru

Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 61, Visits: 35
Hi,

Thank you for the fast reply. I changed the code a bit to suit for my application but after trying unfortunately it does not work as I think it should. I changed to code to this:

public void AddDataPoint(int graphNumber, double graphValue, DateTime time)
{
NChart chart = nChartControl1.Charts[0];
NXYScatterSeries series = (NXYScatterSeries)chart.Series[graphNumber];

int i = series.XValues.Count-1;

while (i > 0 && DateTime.FromOADate((double)series.XValues[i]) > time)
{
i--;
}

if (i < 0)
{
i = 0;
}

series.XValues.Insert(i, time);
series.Values.Insert(i, graphValue);
}
It is basically the same.

Please find attached the example picture which I have made while I was testing the solution.

In the firs picture I show the graph which I generated at start up.
In the second picture I add some points in random time between the set time range.

Regards
Daniel

Attachments
graphAtThebegining.png (135 views, 20.00 KB)
graphAfterAddingFewPoints.png (133 views, 22.00 KB)


Similar Topics


Reading This Topic