Realtime UI and LiveCharts update in MVVM

I'm trying to implement a real-time plot UI, i'm using WPF with the MVVM Pattern and Live-Charts by beto-rodriguez as my plot library, but i have some trouble with updating the graphs in real time. I know that i have to run multiple threads to update the UI in realtime, but every single way i tried doesn't work (i'm learning C# now). I'm confused of how i should properly implement this pattern for the realtime update, and if the plot library is able to do that.

This is my actual code (its a simplified version of what i will do and doesn't implement any multithread code)

ModelView Code:

using System;
using System.ComponentModel;
using System.Windows;
using LiveCharts;

    namespace TestMotionDetection
        class MainViewModel : INotifyPropertyChanged
            public SeriesCollection Series { get; set; }

            public Func<double, string> YFormatter { get; set; }
            public Func<double, string> XFormatter { get; set; }

            public DataViewModel SData

            public event PropertyChangedEventHandler PropertyChanged;

            public MainViewModel()
                SeriesConfiguration<DataViewModel> config = new SeriesConfiguration<DataViewModel>();
                config.Y(model => model.Value);
                config.X(model => model.Time);

                Series = new SeriesCollection(config)
                    new LineSeries {Values = new ChartValues<DataViewModel>(), PointRadius = 0}

                XFormatter = val => Math.Round(val) + " ms";
                YFormatter = val => Math.Round(val) + " °";

            protected virtual void OnPropertyChanged(string propertyName)
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

            public void generateData()
                DataViewModel val = new DataViewModel();
                for (int i = 0; i < 500; i++)
                    val.Time = i;
                    val.Value = i + 2.3f;
                    SData = val;

Here is the View code:

using System.Windows;

namespace TestMotionDetection
    /// <summary>
    /// Logica di interazione per MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        private MainViewModel vista;

        public MainWindow()
            vista = new MainViewModel();
            DataContext = vista;

        private void button_Click(object sender, RoutedEventArgs e)

And the XALM:

<Window x:Class="TestMotionDetection.MainWindow"
        Title="Example 2  (WPF)"

        <lvc:LineChart Margin="0,2,245,-2"
                       Series="{Binding Series}">
                <lvc:Axis LabelFormatter="{Binding XFormatter}" Separator="{x:Static lvc:DefaultAxes.CleanSeparator}" />
                <lvc:Axis LabelFormatter="{Binding YFormatter}" />
        <Button x:Name="button"
                Content="Button" />

[UPDATE 1] []1


Your XFormatter & YFormatter should both be like this:

private Func<double, string> _yFormatter;
public Func<double, string> YFormatter { 
    get{ return _yFormatter; }
        _yFormatter = value;

If you are using C#6 you should do nameof(YFormatter) instead.

That will cause the view to update, otherwise the view has no way of knowing that the formatter changed.

Need Your Help

Creating a data frame in R from a list of instances

r web-scraping dataframe

I scraped a list of data from a website and have used the following code to convert it to a list in R. Now that I have converted it into a list with elements I cannot get it into a matrix/data fram...