Adding dynamic mean to time series chart

让人想犯罪 __ 提交于 2019-12-02 08:28:32
jlbriggs

Using a combination of the answer here:

And an example of dynamic average using all visible series that I made for a previous question, here:

I put together this example, using the afterSetExtremes event, like 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 the afterSetExtremes event

2) get the resulting axis min and max

3) loop through the series data

4) if a point is between the min and max, increment the count, and add the point's y value to the sum

5) calculate the average accordingly, check for existence of average series, if exists, update, if not, add

It could as easily use a plot line that you add/remove as needed instead of a series, but I like having it as a series so that it has a legend entry.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!