What is ObservableValue in LiveChart

2.8k views Asked by At

I do not understand ObservableValue, or what is the difference between passing in an ObservableValue and passing in the original value/type itself?

If I take the following as an example, be it ObservableValue or a double type, the Chart would dynamically populate the random value and update the chart including the animation.

So why ObservableValue? And could someone suggest an example.

Values = new ChartValues<ObservableValue>
{
    new ObservableValue(r.Next(10, 400)),
};

Values = new ChartValues<double>
{
    (r.Next(10, 400)),
};
2

There are 2 answers

0
mm8 On BEST ANSWER

If you intend to update an individual value within the Values collection dynamically at runtime after you have populated the initial collection and displayed the chart, you need to use ObservableValue for the chart to be able to notify this update and update itself accordingly.

There is no event raised when you simply replace a double value in the collection like this:

Values[0] = 1.0;

...but if you set the Value property of an ObservableValue like this, a PropertyChanged event is raised:

Values[0].Value = 1.0;

The chart subscribes to the PropertyChanged event to listen for updates. That's the difference.

0
Il Vic On

If you use an ObservableValue, it simply notifies the chart to update every time its Value property changes (since it implemtents INotifyPropertyChanged interface).

You can find ObservableValue source here