Highcharts多个系列+类别 - PHP / JSON

时间:2014-10-15 12:48:09

标签: javascript php jquery json highcharts

我有data.php输出(每个开始/结束时间更改日期)

{"success":1,"data":[{"name":"John Spoon","data":[[0,3],[1,0],[2,2],[3,1],[4,0]]}, {"name":"Dave Jones","data":[[0,0],[1,3],[2,2],[3,0],[4,0]]}],"dates":[[0,"01\/09\/2014 - 08\/09\/2014"],[1,"08\/09\/2014 - 15\/09\/2014"],[2,"15\/09\/2014 - 22\/09\/2014"],[3,"22\/09\/2014 - 29\/09\/2014"],[4,"29\/09\/2014 - 06\/10\/2014"]]}

如何在highcharts折线图中显示这一点,我试过这个但是没有任何反应,但是等待,加载图表......':

<div id="chart"></div>

<input type="button" value="Show HighChart" onclick="InitHighChart();" />
<script>
function InitHighChart()
{
    $("#chart").html("Wait, Loading graph...");

    var options = {
        chart: {
            renderTo: 'chart',
        },
        credits: {
            enabled: false
        },
        title: {
            text: 'Impression/Click Overview',
            x: -20
        },
        xAxis: {
            categories: [{}]
        },
        tooltip: {
            formatter: function() {
                var s = '<b>'+ this.x +'</b>';

                $.each(this.points, function(i, point) {
                    s += '<br/>'+point.series.name+': '+point.y;
                });

                return s;
            },
            shared: true
        },
        series: [{},{}]
    };

    $.ajax({
        url: "http://localhost/php/data.php?start_date=01%2F09%2F2014&start_time=00&end_date=02%2F10%2F2014&end_time=23",
        type:'post',
        dataType: "json",
        success: function(data){
            options.xAxis.categories = data.ticks;
            options.series = data.data;
            var chart = new Highcharts.Chart(options);          
        }
    });

}
</script>

我想要的结果就像这个http://jsfiddle.net/p4hp1drj/但是从文件data.php中使用json编码的PHP

json代码中的值之前的数字是需要单独但只是增量的。

0 个答案:

没有答案