高图多个 y 轴和动态更新

Highcharts multiple y axis and dynamic update

本文关键字:动态 更新 高图多      更新时间:2023-09-26

我正在尝试做这种类型的图表,我修改并结合了这两个示例。这是jsfiddle的结果:http://jsfiddle.net/cp0ux9qp/4/

$(function () {
    $(document).ready(function () {
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });
        $('#container').highcharts({
            chart: {
                zoomType: 'xy',
                type: 'spline',
                animation: Highcharts.svg, // don't animate in old IE
                marginRight: 10,
                events: {
                    load: function () {
                        // set up the updating of the chart each second
                        var serie1 = this.series[0];
                        var serie2 = this.series[1];
                        setInterval(function () {
                            var x = (new Date()).getTime(), // current time
                                y = Math.floor((Math.random() * 10) + 5),
                                z = Math.floor((Math.random() * 20) + 15);
                            serie1.addPoint([x, y], true, true);
                            serie2.addPoint([x, z], true, true);
                        }, 1000);
                    }
                }
            },
            title: {
                text: 'Oxygen and Temperature'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150
            },
            yAxis: [{ // Primary yAxis
                labels: {
                    format: '{value}mg/L',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
                title: {
                    text: 'Oxygen',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                }
            }, { // Secondary yAxis
                title: {
                    text: 'Temperature',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                labels: {
                    format: '{value}C',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                opposite: true
            }],
            tooltip: {
            shared: true
        },
            legend: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            series: [{
                name: 'Oxygen',
                data: (function () {
                    // generate an array of random data
                    var data = [],
                        time = (new Date()).getTime(),
                        i;
                    for (i = -19; i <= 0; i += 1) {
                        data.push({
                            x: time + i * 1000,
                            y: Math.floor((Math.random() * 10) + 5)
                        });
                    }
                    return data;
                }())
            },
                     {
                name: 'Temperature',
                data: (function () {
                    // generate an array of random data
                    var data = [],
                        time = (new Date()).getTime(),
                        i;
                    for (i = -19; i <= 0; i += 1) {
                        data.push({
                            x: time + i * 1000,
                            y: Math.floor((Math.random() * 20) + 15)
                        });
                    }
                    return data;
                }()),
                yAxis:1
            }
            ]
        });
    });
});

它没有显示次要 Y axi,为什么?当数据在一段时间内相同时,会出现另一个问题,例如:氧气:6.74温度: 16.7修改了 X 轴刻度,图形仅显示一条线。

隐藏辅助轴的问题是因为在容器样式属性 + chart.marginRight: 20中使用最小宽度声明,您将轴绘制为div。如果注释掉边距,则会看到辅助轴。

至于当您具有相同的缩放温度/氧气含量时 - 它应该如何表现?