简体   繁体   English

Highcharts JSON,图表未显示

[英]Highcharts JSON, chart not displaying

I have some data I wish to display on a chart but it just shows the title and no points get drawn. 我有一些数据希望显示在图表上,但仅显示标题,而不会绘制任何点。 The JSON data I receive is correct as per my knowledge, I think it's somewhere in the chart function but I can't really point it out. 据我所知,我收到的JSON数据是正确的,我认为它在图表函数中的某处,但我无法真正指出。

This is what I have so far: data.php (the output): 到目前为止,这是我所拥有的:data.php(输出):

{"name":"Temperature","data":[34,28,29,28,34,28,32,27,24,30,25,32,34,28,34,33,24,33,30,27,24,27,26,29]}

The important bits of the html: html的重要部分:

<script>
    $(function () {
    var chart;
    $(document).ready(function() {
        $.getJSON("data.php", function(json) {
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container',
                    type: 'line',
                    marginRight: 130,
                    marginBottom: 25
                },
                title: {
                    text: 'Temperature vs. Time',
                    x: -20 //center
                },
                xAxis: {
                    categories: ['12AM', '1AM', '2AM', '3AM', '4AM', '5AM', '6AM', '7AM', '8AM', '9AM', '10AM', '11AM','12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM', '10PM', '11PM']
                },
                yAxis: {
                    title: {
                        text: 'Temperature'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                series: json
            });
        });
    });    
});
</script>

It's supposed to show temperature per hour but unfortunately nothing comes up. 它应该显示每小时的温度,但是不幸的是没有任何反应。 Any idea what could be wrong? 知道有什么问题吗?

series should be an array. series应该是一个数组。 So you need to just change: 因此,您只需要更改:

series: json

To: 至:

series: [json]

Working example: http://codepen.io/anon/pen/Kfgsd 工作示例: http : //codepen.io/anon/pen/Kfgsd

Documentation: http://www.highcharts.com/docs/chart-concepts/series 说明文件: http : //www.highcharts.com/docs/chart-concepts/series

您的问题我认为您尚未指定图表应插入的位置,因此您应该为类构造函数选项指定renderTo选项,或使用$('#container').haighcharts({...}) jQuery助手

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

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