문제

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?

도움이 되었습니까?

해결책

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

다른 팁

your problem i think that you haven't specified where your chart should be inserted to, afaik you either should specify the renderTo option for the class constructor options or use the $('#container').haighcharts({...}) jquery helper

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top