簡體   English   中英

canvasJS:圖表未加載

[英]canvasJS : the chart isnt loaded

這實際上是我第一次使用canvajs,但確實可以使用:(有人可以檢查我的代碼嗎

data.php

<?php 

header('Content-Type: application/json');

include './traitement.php';

$data =array();

$data=getListTemp();

$point=array();

$data_points=array();

foreach($data as $value){ foreach($value as $l){

        $s= explode( 'T', $l->date) ;

        $t=explode('-',$s[0]);

        $f=explode(':',$s[1]);

        $io=explode('+',$f[2]);

        $o=mktime($f[0],$f[1],$io[1],$t[1],$t[2],$t[0]);

        $i= date ("D M Y H:i:s U", $o);

        $point = array("x" => $i, "y" => $l->valeur);

        array_push($data_points, $point);        
}}

echo json_encode($data_points, JSON_NUMERIC_CHECK);

?>

結果:

[{“ x”:“ Sat Jul 2017 23:20:01”,“ y”:30},{“ x”:“ Sat Jul 2017 23:10:01”,“ y”:30},{“ x “:” Sat Jul 2017 23:00:01“,” y“:30},{” x“:” Sat Jul 2017 22:50:01“,” y“:25},{” x“:” Sat Jul 2017 22:40:01“,” y“:30},{” x“:” Sat Jul 2017 22:30:01“,” y“:25},{” x“:” Sat Jul 2017 22: 20:01“,” y“:30},{” x“:” Sat Jul 2017 22:10:01“,” y“:40},{” x“:” Sat Jul 2017 22:00:01“ , “Y”:23}]

curve.html

<!DOCTYPE html>
<html>


<head>
    <title></title>

    <script src="canvasjs.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script src="http://code.jquery.com/jquery-latest.js" > </script>

    <script type="text/javascript">

$(document).ready(function () {
$.getJSON("data.php", function (result) {

 var dps=[]; 
 dps = result;

     var chart = new CanvasJS.Chart("chartContainer",{
        title :{
            text: "Data "
        },
        axisX: {                        
            title: "time",

        },
        axisY: {                        
             title: "temperature",

        },
        data: [{
            type:"spline",

            dataPoints : dps
        }]
      });

     chart.render();    


});

});

    </script>
</head>
<body>

    <div id="chartContainer" style="width: 800px; height: 380px;"></div>

</body>
</html>

那就是我的結果! 在此處輸入圖片說明

用標簽替換x。 根據文檔和我嘗試過的東西,x只能是一個數字,然后它才能工作,並且在您的情況下,它是字符串“ Sat jul ..”,因此將x標記為標簽

(下面是我上面的評論的復制粘貼)在“ x”中使用“ label”作為響應,我閱讀了文檔並嘗試使用此jsfiddle.net/p7w58naq與您的響應

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM