简体   繁体   English

Highstock,在setExtreme(缩放)后获取显示点计数的真实方法-无需用MIN和MAX计数所有数据

[英]Highstock, True way of Get count of shown points after setExtreme (Zooming) - WITHOUT counting all data with MIN and MAX

Sure there is a way to count all of points that shown after zooming or any changing view and do reaction for that. 当然,有一种方法可以对缩放或任何变化的视图后显示的所有点进行计数,并对此做出反应。

My target is in Highchart 7.2.0 stockChart , IF "viewed points" x "radius of circles" , gone more than (>) "view-port pixels" , i just hide them, or doing something special with points, because some of them are Special and still should be shown. 我的目标是在Highchart 7.2.0 stockChart中如果 视点 x “圆半径”大于(>) “视口像素” ,我只是将其隐藏起来,或者对点做一些特殊的处理,因为它们是特殊的,仍应显示。

so i need : 所以我需要:

  1. HOW GET : Count of points that JUST viewed now (WITHOUT PUTTING A "FOR" TO ALL OF DATA's) 如何获取: 现在仅查看的点数 (无需为所有数据添加“ FOR”)

(I just think if there is no true way for it, it is better to i count svg objects instead of : counting all of my data and using isInside with min and max ) (我只是觉得如果它没有真正的办法,最好是我算SVG的对象,而不是: 计数我所有的数据,并使用isInside最小值最大值

  1. The Best Events for : " afterSetExtremes " and " events :{ redraw :" [Solved i think] 最佳活动:“ afterSetExtremes ”和“ 事件 :{ 重绘 :” [解决我认为]
              events: {
                afterSetExtremes: function(event) {
                      console.log(event.min);
                      console.log(event.max);
                  }
              }
  1. How i turn them off [Solved i think] 我如何关闭它们[解决了我认为的问题]
                    if (chart.userOptions.plotOptions.line.marker.enabled) {
                        chart.userOptions.plotOptions.line.marker.enabled=false;
                        chart.update({
                            plotOptions: {
                                marker: {
                                    enabled:false
                                }
                            }
                        });
                    }
  1. If there is automatic way like "amchart" options that i just ask " marker : { enabled: true " (when no problem) and " marker : { enabled: false " when it is tight. 如果有像“ amchart”这样的自动方式,我只问“ marker :{enabled: true ”(没有问题)和“ marker :{enabled: false ”。 [Solved i think] [解决我认为]

Solved by this: 解决了这个问题:

        plotOptions: {
            series: {
                marker: {
                    enabled:undefined,
                    enabledThreshold: 4,
                    symbol: 'circle',
                    radius: 4,
                },
            }
        }

It was like this : 就像这样:

marker: {enabled: true , enabledThreshold: 0, (By Default) 标记:{enabled: true ,enabledThreshold:0,(默认)

Should be : 应该 :

marker: {enabled: undefined , enabledThreshold: 4 , (More than Zero) 标记:{enabled: undefined ,enabledThreshold: 4 ,(大于零)

Got help from here : https://stackoverflow.com/a/54417034/7514010 从这里获得帮助: https : //stackoverflow.com/a/54417034/7514010

The easiest way is to loop through the data and check isInside point property or point position. 最简单的方法是遍历数据并检查isInside点属性或点位置。 As an alternative you can overwrite translate method and count the number of visible points in the existing loop: 或者,您可以覆盖translate方法并计算现有循环中的可见点数:

var counter;

(function(H) {
    H.Series.prototype.translate = function() {
        ...

        counter = 0;
        // Translate each point
        for (i = 0; i < dataLength; i++) {
            ...
            point.isInside =
                plotY !== undefined &&
                plotY >= 0 &&
                plotY <= yAxis.len && // #3519
                plotX >= 0 &&
                plotX <= xAxis.len;

            // CHANGE

            if (point.isInside) {
                counter++;
            }

            // CHANGE

            ...
        }
        series.closestPointRangePx = closestPointRangePx;
        H.fireEvent(this, 'afterTranslate');
    }

})(Highcharts)

Live demo: http://jsfiddle.net/BlackLabel/yx1cj0at/ 现场演示: http //jsfiddle.net/BlackLabel/yx1cj0at/

Docs: https://www.highcharts.com/docs/extending-highcharts 文件: https //www.highcharts.com/docs/extending-highcharts

It answered by @ppotaczek here in the third comment by this link jsfiddle.net/BlackLabel/j1tLfaxu and also in GitHub issues : https://github.com/highcharts/highcharts/issues/12017 它由@ppotaczek 在这里通过链接jsfiddle.net/BlackLabel/j1tLfaxu在第三条评论中以及在GitHub问题中得到了答复https : //github.com/highcharts/highcharts/issues/12017

If need to get count of points that just viewed now (by using afterSetExtremes or redraw or render events) : 如果需要获取现在正在查看的点数(通过使用afterSetExtremes重绘渲染事件):

    chart: {
        events: {
            render: function() {
                console.log(this.series[0].points.length)
            }
        }
    },
  • processedXData can be used too instead of points processedXData可得代替
  • points object have enough options like isInside : points对象具有足够的选项,例如isInside
this.series[0].points[0].isInsdie.

Because it is possible the first or last point be not shown and just affect the lines in line chart or in other type of chart be not shown because zooming in Y too. 因为有可能 没有显示第一个点或最后一个点,而只是影响了折线图或其他类型的图表中的线,所以也没有显示出来。

and for just calculation where the extreme started you may need : 为了进行极端计算,您可能需要:

this.series[0].cropStart

and comparing that with your main data. 并将其与您的主要数据进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM