javascript - Adding dynamic mean to time series chart -
i try explain problem accurate possible. looking javascript chart library filling 2 following conditions:
from ajax request retrieving time series, display dynamically data when changing time window.
such done on highstocks: http://www.highcharts.com/stock/demo/basic-line
and
plot horizontal line corresponding mean, changing when user update time window on chart.
actually possible display horizontal line. fixed on whole data , not change accordingly when time window modified:
http://www.highcharts.com/stock/demo/yaxis-plotlines
i quite new topic , know if it'sp ossible modify highstock classes have such result. or maybe other js
libraries exists?
using combination of answer here:
and example of dynamic average using visible series made previous question, here:
i put example, using aftersetextremes
event, this:
xaxis : { events:{ aftersetextremes:function() { var ext = this.getextremes(); getaverage(this.chart, ext.min, ext.max, show, width, avgcolor, dashstyle); } } },
working example here:
the idea is:
1) capture aftersetextremes event
2) resulting axis min , max
3) loop through series data
4) if point between min , max, increment count, , add point's y value sum
5) calculate average accordingly, check existence of average series, if exists, update, if not, add
it use plot line add/remove needed instead of series, having series has legend entry.
Comments
Post a Comment