我做了一个图表,显示机器和它们被固定的时间(机器x,时间y)数据通过mysql动态加载,如下所示
<?php
include_once(“connexion.php”);
ini_set(‘max_execution_time’,300);
//ini_set(‘error_reporting’, E_ALL);
$sq = “select machine,date_tech,time(time_fin – time_deb) as diff 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’];
// $data[] = [“label”=>$machine, “y”=>$diff];
$data[] = array(
‘label’ => $tab[‘machine’],
‘y’ => $tab[‘diff’]
);
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset=”UTF-8”>
<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: “Curative”,
dataPoints: <?php echo json_encode($data); ?>
}
]
});
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: 1920px; margin: 0px auto;”></div>
<script src=”../../canvasjs.min.js”></script>
</body>
</html>
但结果与预期不符
结果:https://i.stack.imgur.com/zyizm.png
你能帮我找出解决这个问题的方法吗:)
1条答案
按热度按时间yhxst69z1#
看起来您是在用y值传递日期和时间,而canvasjs在axisy中只支持数字。有关更多信息,请参阅文档。但是,您可以通过传递-值作为时间戳来解决这个问题,并在轴标签和工具提示中设置值的格式,如下面的示例所示,这里是相同的jsfiddle。