Search code examples
c#wpflivecharts

How to add point one by one to serie in livechart


public ChartValues<ObservablePoint> Series1 { get; set; }

public void GeneratePlot(PlotInfo plotInfo)
{
    DataContext = null;

    Series1 = new ChartValues<ObservablePoint>();
    Series1.AddRange(plotInfo.SeriesIn);

    DataContext = this;
}

How can I add point one and wait 200ms and add next point smoothly?

Now program's UI stop for few second and all points are shown.


Solution

  • Try this:

    public async void GeneratePlot(PlotInfo plotInfo)
    {
        Series1 = new ChartValues<ObservablePoint>();
        DataContext = this;
    
        foreach (var x in plotInfo.SeriesIn)
        {
            Series1.Add(x);
            await Task.Delay(200);
        }
    }