Search code examples
c#wpflivecharts

How to instantiate a list with a specific numbers of values without know the value?


I'm using LiveChart of wpf, and I want instantiate a list of Decimal with 30 values (just as space as an array), actually I did:

public SeriesCollection MonthProfit {get;set;} = new SeriesCollection();

 int i = 0;
 MonthProfit[0].Values = new ChartValues<decimal>();
 MonthProfit[0].Values[i] = 25;

but I get:

Index out of range

how can I define 30 values inside the index 0?


Solution

  • It looks to me like you could use the ChartValues constructor that accepts an IEnumerable<T>:

    MonthProfit[0].Values = new ChartValues<decimal>(Enumerable.Repeat(0m, 30));