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

时间:2022-09-15 09:31:15

I'm using highcharts time series, I need to add another data series populated from a different json file/link, is that possible?

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

Here is my code:

这是我的代码:

$(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
            }
            ]
        });
    });
});

There are examples on the highcharts website, but they are all static data series, I need to have both data series populated from json requests

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

1 个解决方案

#1


2  

Yes you can. Of course, I am hoping I understood your problem.

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

This link shows you how you can add multiple y-axes. As for getting the data. $.when should help you.

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

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

#1


2  

Yes you can. Of course, I am hoping I understood your problem.

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

This link shows you how you can add multiple y-axes. As for getting the data. $.when should help you.

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

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