Highstock: how programmatically sum selected values and show the sum to user

北城余情 提交于 2019-12-12 03:46:00

问题


How Can I sum the points in a line within a selected range in order to be shown to users?


回答1:


Yes it is possible, by means of using afterSetExtremes function (http://api.highcharts.com/highstock#xAxis.events.afterSetExtremes) which allows to catch "change" range event and run custom function. So then you can interate for all points in serie and limit which of them should be added to sum, by check min/max range value.

http://jsfiddle.net/2WdQw/

afterSetExtremes: function(e) {
                var sum = 0,
                    chartOb = this;

                $.each(chartOb.series[0].data,function(i,point){

                    if(point.x >= chartOb.min && point.x <= chartOb.max)
                        sum += point.y;

                });


                $('#report').html('Sum: '+sum);
            }


来源:https://stackoverflow.com/questions/14176459/highstock-how-programmatically-sum-selected-values-and-show-the-sum-to-user

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