Updating spline chart two lines on top of eachother

 ̄綄美尐妖づ 提交于 2019-12-13 21:02:50

问题


I am showing two lines in a single graph updating them each second with a value that is saved into a global variable (both have different global variables). An example of the code can be found here: jsFiddle example.

As you can see the two lines are on top of each other, even though they have different values when the ymin and ymax are added to the lines (you can see this in the console).

The cause appears to be in the first addPoint call (line 118). If the first boolean is set to true (like the second addPoint call) the lines are shown correctly but the animation is wrong: jsFiddle example.

Does anyone know why the lines are on top of each other while their values are obviously different? And more importantly: how can I fix this while keeping the smooth animation?

Previous (possibly related) question: Chart not moving fluently when adding value to two lines on interval.


回答1:


The problem is with using the same variable emptyarray for both series. This is known issue with Highcharts (roported on github) that Highcharts overwrites some of options passed to the chart. Possible solution is to use function which will return that empty array, for example:

    function generateArray(){
        var emptyarray = [],
            time = (new Date()).getTime(),
            i;

        for (i = -50; i <= 0; i++) {
            emptyarray.push({
                x: time + i * 1000,
                y: 230
            });
        }
        return emptyarray;
    }

    chartinfo.series = [{
        name: 'Minimum Voltage',
        data: generateArray(),
        color: '#FFFFDD'
    }, {
        name: 'Maximum Voltage',
        data: generateArray(),
        color: '#B72E8D'
    }];

Working jsFiddle: http://jsfiddle.net/XAHa4/2/




回答2:


It looks like strange with your setInerval functions, because minified example http://jsfiddle.net/DxqUj/ works properly.



来源:https://stackoverflow.com/questions/16920774/updating-spline-chart-two-lines-on-top-of-eachother

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