我有问题。我正在使用“ChartJS”制作图表。数据来自MYSQL数据库和标签。
在我的代码中获取数据没有问题,但是使用标签。任何人都可以找到错误,为什么它不起作用?
<script>
var randomScalingFactor = function () {
return Math.round(Math.random() * 100)
};
var lineChartData = {
labels: [<?php foreach ($pdo->query("SELECT * FROM wetterdaten WHERE datum = '$datum'") as $row) {
$uhrzeit = $row['uhrzeit'];
echo """ . $uhrzeit . "", ";
} ?>],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [<?php foreach ($pdo->query("SELECT * FROM wetterdaten WHERE datum = '$datum'") as $row) {
$luftfeuchtigkeit = $row['luftfeuchtigkeit'];
echo $luftfeuchtigkeit . ",";
} ?>]
}
]
}
window.onload = function () {
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true
});
}
</script>
在“标签”中有错误,因为,当我手动编写时间时,如:
labels : ["13:05","14:01"],
它工作正常!但它不适用于MySQL-Statement。