I am trying to create a moving average over the rest of the chart. I am trying to do something similar to this.
However, for my data points I continuously get the error:
"Error: Invalid value for attribute d="M1.2121212121212122,NaNL1.4141414141414141,NaNC1.6161616161616161,NaN,2.0202020202020203,NaN,2.4242424..."
I believe it is because my data isn't formatted correctly, but I don't know how to modify the function to work with my data. My data currently looks like:
var data = [ {"x": 1, "y": 113},
{"x": 6, "y": 38},
{"x": 11, "y": 108},
{"x": 16, "y": 245},
{"x": 21, "y": 155},
{"x": 26, "y": 234},
...
Thanks
Just map your [{x1,y1}, {x2,y2}, ... {xN,yN}] pairs to a [y1, y2, ... yN] series, which is what that moving average function expects:
movingAverageLine(data.map(function(d) { return d.y; }))
Here's a working fiddle: http://jsfiddle.net/yz87b53d/3/
You should accept meetamit's answer since that essentially was the issue.
movingAverageLine(data.map(function(d) { return d.y; }))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With