OxyPlot not refreshing when using data binding in WPF

和自甴很熟 提交于 2019-12-06 06:35:49

OxyPlot does not automatically update when you add data.

You must call plotname.InvalidatePlot(true);

and it must run on the UI dispatcher thread, ie

Dispatcher.InvokeAsync(() => 
{
    plotname.InvalidatePlot(true);
}

Don't know if people still need this but I was having the same problems with itemsource not updating chart. And none of the existing solutions helped me.

Well I've finally found the reason why whole thing didn't work. I've assigned my collection to itemsource before I actually initialized it (new Observable....).

When i tried assigning already initialized collection to my itemsource, whole thing started working.

Hope this helps someone.

I know this is an old question but maybe someone will use my answer after hours of double checking. I use MVVM. I'm updating the data with await Task.Run(()=> update()); and that wasn't rendering my plot in my UI. I was also initializing my PlotModel before setting it. Turns out, initializing the PlotModel in that update() method wasn't registering in my UI. I had to initialize it before I called that Task to run.

public ViewModel()
{
     Plot = new PlotModel(); //(Plot is a property using 
                             // INotifyPropertyChanged)
     PlotGraph = new RelayCommand(OnPlotGraph);
}

public RelayCommand PlotGraph {get; set;}

private async void OnPlotGraph()
{
     await Task.Run(() => Update());
}

private void Update()
{
    var tempPlot = new PlotModel();
    //(set up tempPlot, add data to tempPlot)
    Plot = tempPlot;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!