Adding dynamic mean to time series chart

后端 未结 1 1415
[愿得一人]
[愿得一人] 2021-01-26 09:24

I will try to explain my problem as much accurate as possible. I am looking for a javascript chart library filling the two following conditions:

From an ajax req         


        
相关标签:
1条回答
  • 2021-01-26 09:56

    Using a combination of the answer here:

    • Highchart, get total of visible series data after setExtremes

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

    • http://jsfiddle.net/jlbriggs/gweuLegq/

    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:

    • http://jsfiddle.net/jlbriggs/c93543yL/

    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.

    0 讨论(0)
提交回复
热议问题