它实际上是我第一次使用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);
?>
结果:
[{&#34; x&#34;:&#34; 2017年7月17日星期六23:20:01&#34;,&#34; y&#34;:30},{&#34; x&#34 ;:&#34; 2017年7月17日星期六23:10:01&#34;,&#34; y&#34;:30},{&#34; x&#34;:&#34; 2017年7月17日23:00 :01&#34;,&#34; y&#34;:30},{&#34; x&#34;:&#34; 2017年7月22日星期六22:50:01&#34;,&#34; y&# 34;:25},{&#34; x&#34;:&#34; 2017年7月7日星期六22:40:01&#34;,&#34; y&#34;:30},{&#34; x& #34;:&#34;星期六2017年7月22:30:01&#34;,&#34; y&#34;:25},{&#34; x&#34;:&#34;星期六2017年7月22日:20:01&#34;,&#34; y&#34;:30},{&#34; x&#34;:&#34;星期六2017年7月22:10:01&#34;,&#34; y&#34;:40},{&#34; x&#34;:&#34; 2017年7月22日星期二22:00&#34;,&#34; y&#34;: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>
这就是我的结果!! enter image description here
答案 0 :(得分:0)
用标签替换x。根据文件和我试过的东西x应该是一个数字然后它才会起作用,在你的情况下它是字符串&#39; Sat jul ..&#39;所以将x标记为标签
(以下是我上述评论的复制粘贴) 代替&#39; x&#39;使用&#39;标签&#39;作为回应,我阅读了文档,并在您的回复中尝试了这个jsfiddle.net/p7w58naq