缩放时对一对图表进行动态更新

Dynamic updates on a pair of charts when zoomed

本文关键字:动态 更新 缩放      更新时间:2023-09-26

(JsFiddle here)

我有一对具有公共逻辑x轴的时间序列图表,它们使用series.addPoint()更新。使用aftersetextrees()事件,我已经设置了一些东西,以便放大一个图表上的区域也会放大第二个图表的相同区域,如下所示:

    xAxis: {
    events: {
        afterSetExtremes: function (e) {
            if (chart2) {
                // if 'Reset Zoom' has been clicked, we need to call chart.zoomOut()
                // instead of setExtremes, otherwise new points added to the series 
                // dynamically are not shown.
                if (e.min <= e.dataMin && e.max >= e.dataMax) {
                    var ex = xaxis2.getExtremes();
                    if (ex.min > e.dataMin || ex.max < ex.dataMax) {
                        chart2.zoomOut();
                    }
                // call setExtremes if necessary (note: condition also prevents
                // infinite loop between the afterSetExtremes methods of both charts)
                } else if (xaxis2.min != e.min && xaxis2.max != e.max) {
                    xaxis2.setExtremes(e.min, e.max);
                }
            }
        }
    }
},

这工作得很好,但是当我放大任何一个图表的某些区域,其中包括图表的极右端(以便最近添加的点可见),动态添加到系列的新点只显示在最初放大的图表上,而另一个图表只是保持固定放大在原始缩放区域(即,新的点不显示)。

我需要做什么才能让第二个图表显示动态更新,就像第一个图表所做的那样?

您需要呼叫setExtremes

http://jsfiddle.net/A9xjh/4/

http://jsfiddle.net/A9xjh/5/