6

I am currently creating a project which wil grab live data from a COM port for me and then display it for easy interpretation. Part of that is creating line graphs with Dynamic Data Display, which I want to happen live as well.

I currently have a working setup that pulls together data from a collection and outputs it in a readable format for the plotter, while this is just fine for my static sample data, I fear this is far from optimized considering that the data will update a lot (sometimes multiple times per second). Always sending a notification that data changed makes the graph refresh, but always pulling all data and creating a new graph source seems far from efficient. I'm using the following code in my view model:

private CompositeDataSource _AccelXData;
public CompositeDataSource AccelXData
{
    get
    {
        var xData = new EnumerableDataSource<int>(dataItems.Select(v => v.id));
        xData.SetXMapping(x => x);
        var yData = new EnumerableDataSource<double>(dataItems.Select(v => v.accelX));
        yData.SetYMapping(y => y);
        _AccelXData = xData.Join(yData);
        return _AccelXData;
    }
}

I have multiple of those running, each representing one graph (e.g. acceleration on the x,y and z axis). They are bound to following example chart:

<d3:ChartPlotter Name="plotter" DockPanel.Dock="Top" Margin="5">
    <d3:LineGraph DataSource="{Binding AccelXData}" />
    <d3:LineGraph DataSource="{Binding AccelYData}" />
    <d3:LineGraph DataSource="{Binding AccelZData}" />
</d3:ChartPlotter>

Two things I would like to know about this: Is it possible to write one function to handle all data output, in a way that I don't have to copy the same code over and over? And more importantly, what would be the best way to simply add values to my line graphs as soon as my Collection updates instead of regathering all data over and over?

Heiko Rothe
  • 331
  • 3
  • 16

0 Answers0