在一个高图表中添加两个 json 数据系列

Add two json data series in one highchart

本文关键字:两个 json 数据 系列 高图表 一个 添加      更新时间:2023-09-26

我正在使用高图表时间序列,我需要添加另一个从不同的json文件/链接填充的数据系列,这可能吗?

这是我的代码:

$(function () {
    $.getJSON('myfirstjson', function (data) {
        mydata = [];
        $('#tvmtgm').highcharts({
            chart: {
                zoomType: 'x'
            },
            title: {
                text: 'TVM/TGM'
            },
            xAxis: {
                type: 'datetime',
                dateTimeLabelFormats : {
                    hour: '%I %p',
                    minute: '%I:%M %p'
                }
            },
            yAxis: {
                title: {
                    text: 'Moves'
                }
            },
            legend: {
                enabled: false
            },
            plotOptions: {
                area: {
                    fillColor: {
                        linearGradient: {
                            x1: 0,
                            y1: 0,
                            x2: 0,
                            y2: 1
                        },
                        stops: [
                            [0, Highcharts.getOptions().colors[0]],
                            [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                        ]
                    },
                    marker: {
                        radius: 2
                    },
                    lineWidth: 1,
                    states: {
                        hover: {
                            lineWidth: 1
                        }
                    },
                    threshold: null
                }
            },
            series: [{
                type: 'area',
                name: 'Total vessel moves',
                data: data
            }
            ]
        });
    });
});

highcharts网站上有示例,但它们都是静态数据系列,我需要从json请求填充两个数据序列

是的,你可以。当然,我希望我理解你的问题。

此链接显示如何添加多个 y 轴。至于获取数据。 $.when应该帮助你。

var data1, data2;
$.when(
    $.getJSON(onurl1, function(data) {
        data1 = data;
    }),
    $.getJSON(onurl2, function(data) {
        data2= data;
    })
).then(function() {
    //use data1 and data2
});