本文介绍了Highstock:如何以编程方式对所选值求和并将总和显示给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将所选范围内的直线上的点求和以显示给用户?

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

推荐答案

是的,可以通过使用afterSetExtremes函数( http://api.highcharts.com/highstock#xAxis.events.afterSetExtremes ),它可以捕获更改"范围事件并运行自定义功能.因此,您可以检查意甲中的所有点,并通过检查最小/最大范围值来限制应将哪些点相加.

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);
            }

这篇关于Highstock:如何以编程方式对所选值求和并将总和显示给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 08:52