Highcharts不在php中显示json数据

时间:2013-09-06 18:51:36

标签: php json highcharts

Json数据未显示在highcharts图表上。 :( 请帮忙..使用完全没有解析的getJSON。 .post的作品显示了msg ..不知道如何解决..我的图形代码..

$(function () {
    var chart;
    $.post("data.php", function(json)
    {
        //alert("Data Loaded: " + json);
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container1',
                type: 'area'
            },
            yAxis: {
                type: 'double',
                min: 0
            },
            xAxis: {
                type: 'datetime',
                labels: {
                    formatter: function () {
                        return Highcharts.dateFormat('%b %y', this.value);
                    },
                    dateTimeLabelFormats: {
                        month: '%b \'%y',
                        year: '%Y'
                    }
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0
            },
            series: json
        });
    });       
});

这是我的PHP代码..获取json数据

$mysql_connect = mysql_connect($db_host, $db_user, $db_pword, $db_name);
$query = "Select DATE_FORMAT(`timestamp`,'%Y,%m,%d') as date, Count(*) as       frequency from table group by date order by date,frequency asc";

if (!$mysql_connect)  die("unable to connect to database: " . mysql_error());
@mysql_select_db($db_name) or die( "Unable to select database");

$result = mysql_query($query);
$response = array();

if($result === FALSE)
{
    die(mysql_error());
}

echo "[";
$results = array();
while($row=mysql_fetch_array($result))
{
    $results[] = "[Date.UTC(".$row ['date']."),".$row['frequency']."]";
}

echo implode(',',$results); 
echo "]";
mysql_close($mysql_connect);

1 个答案:

答案 0 :(得分:1)

更改系列作业:

    series:[{
        data: json
    }]

http://jsfiddle.net/bDREA/

另外,我会更改你的php代码来构建实际的数组然后json_encode它而不是创建一个字符串。