duanruanxian5028 2013-12-05 23:54
浏览 70
已采纳

Highcharts JSON,图表不显示

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.

This is what I have so far: data.php (the output):

{"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:

<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?

  • 写回答

2条回答 默认 最新

  • dpyln64620 2013-12-06 00:11
    关注

    series should be an array. So you need to just change:

    series: json

    To:

    series: [json]

    Working example: http://codepen.io/anon/pen/Kfgsd

    Documentation: http://www.highcharts.com/docs/chart-concepts/series

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥15 this signal is connected to multiple drivers怎么解决
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥60 关机时蓝屏并显示KMODE_EXCEPTION_NOT_HANDLED,怎么修?
  • ¥66 如何制作支付宝扫码跳转到发红包界面