I would suggest you to check if a value is out of range.
Every time you get a new value you can check if the previous value is out of range with a given tolerance.
If yes, set its value to the mean value between the last and the value before the suspicious value.
You could also calculate a tendency curve with the last three values.
When you get a new value, calculate the linear tendency with last two points or the polynomial tendency curve with the last three points.
Calculate the expected new value and if the new real value is out of range set it to expected value.
Or you could use the Exponential smoothing, but this is more useful for noisy signals, but your case is more about really wrong out of range values.
The equation is : yd[t] = yd[t-1] + Kt * (ys[t] - yd[t-1])
Where
Kt is the smoothing factor between 0 and 1. 1 means no smoothing
ys[t] = current source value
yd[t] = new smoothed destination value
yd[t-1] = previous smoothed destination value at t - 1
This smoothing is similar to a low pass filter and introduces a kind of delay.
Attached a small test program with Exponential smoothing.
It uses the xChartLite class version 1.5 not yet published.
I first used the xChart library and then checked with the xChartLite library.