繁体   English   中英

Highcharts数据导入JSON-格式

[英]Highcharts data import JSON - formatting

我正在尝试获取一些数据以使用Highcharts绘制散点图。 这是数据样本。

{ "results": [ [ "2013-04-14 10:00", -1 ], 
               [ "2013-04-14 11:48", 0 ], 
               [ "2013-04-14 14:45", -1 ], 
               [ "2013-04-14 18:02", -1 ], 
               [ "2013-04-14 18:45", -1 ], 
               [ "2013-04-14 19:57", -1 ], 
               [ "2013-04-14 22:19", 0 ], 
               [ "2013-04-14 23:00", 0 ],
               [ "2013-04-14 23:00", -1 ], 
               [ "2013-04-14 23:00", 0 ], 
               [ "2013-04-14 23:00", 0 ], 
               [ "2013-04-14 23:00", 0 ], 
               [ "2013-04-14 23:00", 0 ], 
               [ "2013-04-14 23:00", 0 ], 
               [ "2013-04-14 23:00", 0 ], 
               [ "2013-04-15 00:18", 0 ], 
               [ "2013-04-15 00:21", 0 ], 
               [ "2013-04-15 00:22", 0 ], 
               [ "2013-04-15 00:24", 1 ], 
               [ "2013-04-15 04:15", -1 ], 
               [ "2013-04-15 09:02", -1 ] 
             ] 
}

这是js:

$(document).ready(function() {
  var options = {

    chart: {
        renderTo: 'container',
        type: 'scatter',
        zoomType: 'xy'
    },
    title: {
        text: 'Sentiment Report by Publish Date'
    },
    subtitle: {
        text: 'Written by Kat Chilton for Oxyme'
    },
    xAxis: {
        title: {
            text: 'Publish Date'
        },
        type: 'datetime'
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Sentiment',
            align: 'high'
        },
        labels: {
            overflow: 'justify'
        }
    },
    plotOptions: {
        scatter: {
            marker: {
                radius: 5,
                states: {
                    hover: {
                        enabled: true,
                        lineColor: 'rgb(0,0,0)'
                    }
                }
            },
            states: {
                hover: {
                    marker: {
                        enabled: false
                    }
                }
            },
            allowPointSelect: true,
            dashStyle: 'dot',
        }
    },
    legend: {
        layout: 'vertical',
        align: 'left',
        verticalAlign: 'top',
        y: 0,
        floating: true,
        borderWidth: 1,
        backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
        shadow: true
    },
    credits: {
        enabled: false
    },
    series: [{}]
};
 $.getJSON('sample.json', function(data) {
    options.series[0].data = data;
    var chart = new Highcharts.Chart(options);
});

我没有在页面上显示任何点,但是图表确实显示了标题和其他内容。 我认为这是数据格式化的问题,但我似乎找不到原因。 有人可以帮忙吗?

您需要从data获取results属性,像这样

options.series[0].data = data.results;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM