dongzanghong4379 2017-04-25 08:50
浏览 55

Highcharts,$ .getJSON,没有运行图表

i try to show in a line Highchart some values passed from a php file `"highchartsFixData.php", that give me :

[{"name":"Month","data":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]},{"name":"Umidita","data":[29.9,71.5,106.4,129.2,144,176,135.6,148.5,216.4,194.1,95.6,54.4]}]

i don't know if this is correct way to pass the data array, or there is something wrong in the code below..

this is the highchartsFixData.php

<?php   
$rows = array();
$rows['name'] = 'Month';
$rows1 = array();
$rows1['name'] = "Umidita"; 

$rows["data"] =  ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
$rows1["data"] = [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4];
$rst = array();

array_push($rst,$rows);
array_push($rst,$rows1);

print json_encode($rst, JSON_NUMERIC_CHECK);
?>

this is index.htm :

<pre>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Static Data</title>

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
var option={
        chart: {
            renderTo: 'container',
            type: 'line',
            marginRight: 130,
            marginBottom: 25
        },
        title: {
            text: 'Highcharts Test',
            x: -20 //center
        },
        subtitle: {
                text: '',
                x: -20
        }
        xAxis: {
            categories: []
        },
        yAxis: {
            title: {
                text: 'Umidita'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },

        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: json

}

    $.getJSON("highchartsFixData.php", function(json) {

    options.xAxis.categories = json[0]['data'];
    options.series[0] = json[1]['data'];
    chart = new Highcharts.Chart(options);          
    });

}); 

</script> 
</head>
<body>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto">
</div>
</body>
</html>
</pre>

index.html doesn't show the chart, and i don't know how i can fix it.. please help me.. thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测