Displaying Dynamic Data / EnumerableDataSource

Jun 29, 2015 at 8:22 PM
Edited Jun 29, 2015 at 8:23 PM
Dear all,

I tried to use EnumerableDataSource because I need to update the graphs multiple times per second.
However I cannot create the chart: "Cannot create a DataSource of given ItemsSource. Look into a list of DataSource types to determine what data can be passed."

This is the relevant part of the code:
        ObservableCollection<Point> points = new ObservableCollection<Point>();
        points.AddMany(Enumerable.Range(0, 9).Select(x => new Point(x, x * x)));

        EnumerableDataSource<Point> ds = new EnumerableDataSource<Point>(points);
        ds.SetXMapping(x => x.X);
        ds.SetYMapping(y => y.Y);

        var chart = plotter.AddLineChart(ds);//it fails here
        chart.Stroke = new SolidColorBrush(DesignColors.Red);
        chart.StrokeThickness = 2;
        chart.Description = "Sensor Value";

        DispatcherTimer dt = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(500) };
        int i = 0;
        dt.Tick += delegate
            points.Add(new Point(i, i * i));

I would greatly appreciate any help on this issue!

Sep 3, 2015 at 7:00 PM
I figured out the solution - was using the wrong EnumerableDataSource class. The correct code is like this:
ds = new DynamicDataDisplay.Markers.DataSources.EnumerableDataSource(points);
ds.DataToPoint = new Func<object, Point>(p => new Point((p as double[])[0], (p as double[])[1]));