<Button Text="Add Series Collection" Clicked="Button_Clicked" />
<chart:SfChart x:Name="chart" Series="{Binding ChartseriesCollection}" /> |
private void Button_Clicked(object sender, EventArgs e)
{
for(int i = 0; i < 5; i++)
{
GenerateSeries();
}
}
private void GenerateSeries()
{
var random = new Random();
var data = new ObservableCollection<ChartDataModel>();
for (int i = 1; i < 5; i++)
{
data.Add(new ChartDataModel(i, random.Next(0, 80)));
}
viewModel.ChartseriesCollection.Add(SetupSeries(new LineSeries(), data));
}
private XyDataSeries SetupSeries(XyDataSeries series, IEnumerable itemSource)
{
series.ItemsSource = itemSource;
series.XBindingPath = "XValue";
series.YBindingPath = "YValue";
return series;
} |