滚动后获取当前可见的图表数据

时间:2019-06-27 13:43:47

标签: javascript react-native highcharts

我在react-native应用程序中使用HighCharts HighStock,并且我尝试获取图表的当前可见数据以使用最新的可见数据刷新工具提示,因此我已经能够加载最新的值,因为它是数据数组的最后一个值,但滚动后无法获取该值。

events: {
      render() {
        const chart = this;
        points = [];


        Highcharts.each(chart.series, (s) => {
          if (s.visible) {
            const lastPoint = s.points[s.points.length - 1];

            if (lastPoint.y === null) lastPoint.y = 0;
            points.push(lastPoint);
          }
        });
        chart.tooltip.refresh(points);
      },

1 个答案:

答案 0 :(得分:0)

您可以使用Highcharts.find方法并检查isInside标志的磅数。如果要避免来自导航器的点,请依次检查isInternal标志。您还应该重置以前悬停的点的状态:

chart: {
    events: {
        render() {
            const chart = this,
                lastPoints = chart.lastPoints,
                points = [];

            if (lastPoints && lastPoints.length) {
                lastPoints.forEach(function(lastPoint) {
                    lastPoint.setState('');
                });
            }

            Highcharts.each(chart.series, (s) => {
                if (s.visible && !s.options.isInternal) {

                    points.push(Highcharts.find(
                        s.points.slice().reverse(),
                        function(p) {
                            return p.isInside ? true : false;
                        }));
                }
            });

            chart.lastPoints = points;
            chart.tooltip.refresh(points);
        }
    }
}

实时演示: http://jsfiddle.net/BlackLabel/xwgs13r6/

API参考:

https://api.highcharts.com/class-reference/Highcharts.Point#setState

https://api.highcharts.com/class-reference/Highcharts#.find