javascript - 在一个highchart中添加两个json数据系列

标签 javascript json highcharts

我正在使用highcharts time series ,我需要添加另一个由不同 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请求填充这两个数据系列

最佳答案

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

This link向您展示如何添加多个 y 轴。 至于获取数据。 $.when应该对你有帮助。

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

关于javascript - 在一个highchart中添加两个json数据系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35201089/

相关文章:

javascript - Chrome & IE : onpaste event not firing?

javascript - 环回由管理员创建用户但由用户更新配置文件

c# - ASP.NET C#,将对象返回给 Angular

javascript - Dojo 单选按钮 - 以编程方式检查其中之一

highcharts - "1"的步进间隔在 Highcharts 中对我不起作用,为什么?

Javascript 空字符串比较

javascript - 如何在 native JavaScript 中使用边距、填充、边框获取元素宽度/高度(无 jQuery)

java - Android从JSON获取特定数据

javascript - 使用 Highcharts 创建一维图表

Highcharts yaxis 标签格式