Search code examples
c#arrayswinformslivecharts

C# Live charts set line series to an array


So in LiveCharts to make a "graph line thingy" you do this:

SeriesCollection = new SeriesCollection
{
    new LineSeries
    {
        Values = new ChartValues<double> { 3, 5, 7, 4 }
    },
    new ColumnSeries                
    {
        Values = new ChartValues<decimal> { 5, 6, 2, 7 }
    }
};

But if I have an array of int-s vals[] how would I set the LineSeries to it?


Solution

  • ChartValues<T> has a constructor that takes IEnumerable<T>, so you can construct LineSeries like this:

    int[] vals = ...
    LineSeries ls = new LineSeries { Values = new ChartValues<int>(vals) };