0

I am trying to use Dynamic Data Display for my senior design project, but I'm having difficulty.

I can create the graph just fine, but I can't the line to update at all unless I am zooming in and out.

In most examples, all they had to do was create the graph, then when they manipulate the data, the graph updates itself.

So here are the main functions I am using with regards to the charts:

    private List<WindDAQ.WindDataPoint> Chart1Data;
    private EnumerableDataSource<WindDAQ.WindDataPoint> Chart1DataSource;

    private void InitializeCharts()
    {
        Chart1Data = new List<WindDAQ.WindDataPoint>();
        Chart1DataSource = new EnumerableDataSource<WindDAQ.WindDataPoint>(Chart1Data);
        Chart1DataSource.SetXMapping(x => Chart1XAxis.ConvertToDouble(x.Time));
        Chart1DataSource.SetYMapping(y => Chart1XAxis.ConvertToDouble(y.Lift));
        Chart1.AddLineGraph(Chart1DataSource, Colors.Blue, 2, "Lift");
        Chart1.Viewport.AutoFitToView = true;
    }




    private void UpdateChart()
    {
        for (int i = 0, count = itsDAQ.getStreamCount(); i < count; i++)
        {
            Chart1Data.Add(itsDAQ.getValue());
            if(Chart1Data.Count >= 300)
            { Chart1Data.RemoveAt(0); }
        }
    }
  • InitializeCharts() is called once when creating the window.

  • UpdateChart() is called on a timer event.

  • WindDAQ.WindDataPoint contains Lift, Drag, Velocity, and Time data. Lift and Time are shown selected.

user2596874
  • 63
  • 1
  • 1
  • 7

1 Answers1

0

you should use the AppendAsync method of your observableCollection. You'r updating only the list used to create the observable one, not the source of your graph.

private void UpdateChart()
{
    for (int i = 0, count = itsDAQ.getStreamCount(); i < count; i++)
    {
        Chart1DataSource.AppendAsync(itsDAQ.getValue());

        if (Chart1DataSource.Collection.Count >= 300) // this part should work in a thread-safe
        { 
           Chart1DataSource.Collection.RemoveAt(0); // context and with some precaution 
        }
    }
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339