简体   繁体   English

canvasJS:图表未加载

[英]canvasJS : the chart isnt loaded

it's actually my first time to use the canvajs but it doenst really work :( could someone please check my code 这实际上是我第一次使用canvajs,但确实可以使用:(有人可以检查我的代码吗

data.php 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);

?>

with the result: 结果:

[{"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}] [{“ 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 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>

And thats what i have as result !! 那就是我的结果! enter image description here 在此处输入图片说明

Replace x with label. 用标签替换x。 As per documentation and things i tried x should be a number only then it will work and in your case it's string 'Sat jul ..' so mark x as label 根据文档和我尝试过的东西,x只能是一个数字,然后它才能工作,并且在您的情况下,它是字符串“ Sat jul ..”,因此将x标记为标签

(below is copy paste of my above comment) In-place of 'x' use 'label' in response , I read the documentation and tried this jsfiddle.net/p7w58naq with your response (下面是我上面的评论的复制粘贴)在“ x”中使用“ label”作为响应,我阅读了文档并尝试使用此jsfiddle.net/p7w58naq与您的响应

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM