我有这张用JavaScript(Canvas Js)制作的图表
代码如下所示
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme:"light2",
animationEnabled: true,
title:{
text: "PM"
},
axisY :{
includeZero: false,
title: "Heures",
suffix: "H"
},
toolTip: {
shared: "true"
},
legend:{
cursor:"pointer",
itemclick : toggleDataSeries
},
data: [
{
type: "spline",
showInLegend: true,
yValueFormatString: "##.00H",
name: "Preventive",
dataPoints: [
{ label: "ABC", y: 2 },
{ label: "DEF", y: 2 },
{ label: "AAA", y: 2 }
]
},
{
type: "spline",
showInLegend: true,
yValueFormatString: "##.00H",
name: "Curative",
dataPoints: [
{ label: "ABC", y: 10 },
{ label: "DEF", y: 2.27 },
{ label: "AAA", y: 1.25 }
]
}]
});
chart.render();
function toggleDataSeries(e) {
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible ){
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
chart.render();
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; max-width: 920px; margin: 0px auto;"></div>
<script src="../../canvasjs.min.js"></script>
</body>
</html>
正如您所说,数据是静态的。
但是,当我想使用mysql查询动态加载数据时
dataPoints: [
<?php
$sq = "select machine,timediff from action_archiv_tech WHERE (date_tech BETWEEN '2018-09-10' AND '2018-10-06')";
$r = mysql_query($sq) or (die(mysql_error()));
while($tab = mysql_fetch_assoc($r)) {
$machine = $tab['machine'];
$diff = $tab['diff'];
?>
{ label: "<?php echo $machine ?>", y: <?php echo $diff ?> }
<?php } ?>
]
页面空白,请您帮我弄清楚哪里出了问题?