【问题标题】:Highcharts JSON, chart not displayingHighcharts JSON,图表不显示
【发布时间】:2013-12-05 23:54:24
【问题描述】:

我希望在图表上显示一些数据,但它只显示标题,没有绘制任何点。据我所知,我收到的 JSON 数据是正确的,我认为它在图表函数中的某个位置,但我无法真正指出。

这是我目前所拥有的: 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]}

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>

它应该显示每小时的温度,但不幸的是什么也没出现。知道有什么问题吗?

【问题讨论】:

  • 在这种情况下,在 codepen.io 或类似网站上进行演示可能会很有用,这样人们就可以快速修改您的代码并找出问题所在

标签: javascript php json highcharts temperature


【解决方案1】:

series 应该是一个数组。所以你只需要改变:

series: json

收件人:

series: [json]

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

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

【讨论】:

    【解决方案2】:

    你的问题我认为你没有指定图表应该插入到哪里,afaik 你应该为类构造函数选项指定renderTo 选项或使用$('#container').haighcharts({...}) jquery 帮助器

    【讨论】:

    • 我在函数中有renderTo: 'container',在html中有另一个div链接到它,如下所示:&lt;div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"&gt;&lt;/div&gt;
    • 哦,对不起,你是对的。我以为你说它根本不渲染任何东西
    猜你喜欢
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多