无法让Axis标签显示在Chart.js中。我已经按照文档进行了操作,但似乎无法让标签显示出来。
图表代码如下所示:
for ($i = 0;$i <= $count; $i++)
{
$query = "SELECT year, brand, model, class, stocknr, price, status, pic
FROM stock WHERE class = 'car' ORDER BY brand ASC";
$result = mysqli_query($con,$query);
$row = mysqli_fetch_assoc($result);
$count=mysqli_num_rows($result);
do {
$title = ("$row[year] "."$row[brand] ". "$row[model]");
$uppic = $row['pic'];
$picloc = "/upload/$uppic";
$price = $row['price'];
$stock = $row['stocknr'];
if (($i == 1) or (($i - 1) % 4) == 0) {
echo '<table><tr>' . "\n";
}
echo "<td>";
echo "<table>";
echo "<tr>";
echo "<br><a href='d.php?stocknr=$stock'>
<span>$title</span></a>";
echo "</tr>";
echo "<tr>";
echo "<a href='d.php?stocknr=$stock'>
<img src='$picloc'></a>";
echo "</tr>";
echo "<tr >";
echo "<br><a href='d.php?stocknr=$stock'>
<span>R$p</span></a>";
echo "</tr></table>";
echo "</td>";
// for 5th, 10th, 15th etc record
if ((($i) % 4) == 0) {
echo '</tr>';
}
while ($i <= $count);
}
图表呈现正常,但x / y轴都没有显示我在设置中设置的轴标签。
这是一个JS小提琴,显示了同样的问题:http://jsfiddle.net/methnen/skfs1fjp/1/
现在已经对我的头撞了一会儿,所以感谢任何人都能帮助我的方式。
答案 0 :(得分:3)
只需在Axes值中添加“[]”括号,如下代码:
"scales": {
"xAxes": [{
"scaleLabel": {
"display": true,
"labelString": "Horizontal Axis"
}
}],
"yAxes": [{
"scaleLabel": {
"display": true,
"labelString": "Vertical Axis"
}
}]
}