0

I am trying to create a light-as-possible real-time plotter with Live Charts Geared WPF, sampling roughly 125 points a second. Adding point-by-point regularly works just fine, except that CPU utilization is much too high.

I would like to draw several points at once, reading in values from a buffer, similar to the website example:

var temporalCv = new double[1000];

for (var i = 0; i < 1000; i++){
    temporalCv[i] = 5;
}

var cv = new ChartValues<double>();
cv.AddRange(temporalCv);

By itself, the example does not throw any issues. However, it throws a cannot convert from double[] to Systems.Collections.Generic.IEnumerable<Object> when I want to AddRange to ChartValues and GearedValues below.

SeriesCollection = new SeriesCollection
            {
                new GLineSeries
                {
                    Title = "Pressure",
                    Values = new GearedValues<double> {},

                },
                new LineSeries
                {
                    Title = "Pulse",
                    Values = new ChartValues<double> { },
                }
            };

SeriesCollection[1].Values.AddRange(temporalCv);

I have also tried changing the array to a GearedValue<double> type but it will still throw the issue when I want to add double values to the array.

Is there anyway to convert double[] or another way to add multiple points to the plot together without erasing old points?

Bondolin
  • 2,793
  • 7
  • 34
  • 62
sophoros
  • 5
  • 5

1 Answers1

0

welcome to Stack Overflow!

It looks like someone else has already asked a similar question here: Convert List<double> to LiveCharts.IChartValues

You will need to convert your double[] to an IEnumerable<double> before you can convert it to an IChartValues collection. This can be easily done with the ToList extension method from System.Linq:

using System.Linq;
...
var chartValues = temporalCv.ToList().AsChartValues();
SeriesCollection[1].Values.AddRange(chartValues);

I do not have LiveCharts so I cannot test this directly. You may only need to convert temporalCv to a list and let AddRange do the rest:

var chartValues = temporalCv.ToList();
Bondolin
  • 2,793
  • 7
  • 34
  • 62
  • So I just changed it to a List instead of array, but AddRange needs an IEnum. I have tried casting and changing it to ChartValues, but the closest I can get it to is IEnum. At least to my understanding, I will have to have an object list and wrap all my inputted doubles as an object? – sophoros Jul 24 '19 at 16:16
  • This works from array to object: https://stackoverflow.com/questions/29922940/converting-double-to-object-in-c-sharp – sophoros Jul 24 '19 at 16:25