Highstock - 从 JSON 文件中提取数据

Highstock - Pulling data from JSON file

我知道在 SO 上有很多与此主题相关的类似问题,但是我未能成功实现我正在尝试做的事情,所以我在这里写了一个问题。请理解我是新人。

所以,基本上,使用 Highstock - 可以在此处找到的基本图表 http://www.highcharts.com/stock/demo/basic-line, I want to import the data from an JSON file named Json1.json. How would I do this? http://jsfiddle.net/x0g8hL0e/1/

在JavaScript中,我写了

$(function () {

    $.getJSON('Json1.json', function (data) {
        // Create the chart
        $('#container').highcharts('StockChart', {


            rangeSelector : {
                selected : 1
            },

            title : {
                text : 'Pressure'
            },

        });
    });

});

此外,是否可以只查看 24 小时制而不是一年制?

P.S,Json数据是这样格式化的

[
{"Pressure": 1},
{"Pressure": 5},
{"Pressure": 3},
{"Pressure": 2},
{"Pressure": 4}
}]

您应该处理您的数据,使其采用 Highcharts 接受的格式。它可以是(如 API reference 中所述):

  1. 一组数值。
  2. 具有 2 个值的数组。
  3. 具有命名值的对象数组。

其他选项是使用定义了 keys 的数组。

如果您想使用例如来自 at 的第一个数据,然后你可以通过你的 JSON 并创建一个数值数组,其中的值来自 Pressure 属性.

$(function () {

    //$.getJSON('Json1.json', function (data) {
    // simulate JSON data
    var data = [{
        "Pressure": 1
    }, {
        "Pressure": 5
    }, {
        "Pressure": 3
    }, {
        "Pressure": 2
    }, {
        "Pressure": 4
    }],
        processedData = [];
    // process the data to match one of formats required by Highcharts - an array of numberical values
    // see: http://api.highcharts.com/highstock#series<line>.data
    Highcharts.each(data, function(d) {
        processedData.push(d.Pressure);
    });
    // Create the chart
    $('#container').highcharts('StockChart', {
        rangeSelector: {
            selected: 1
        },
        title: {
            text: 'Pressure'
        },

        series: [{
            data: processedData
        }]

    });
    //});

});

JSFiddle

有关 Highcharts 的基本信息,您可以查看 General Documentation