$sql = "SELECT count(order_id) as counti, order_date FROM order_detail GROUP BY order_date ORDER BY order_date DESC";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
$dataPoints = [];
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$new_data= array("label"=> $row['order_date'], "y"=> $row['counti']);
$dataPoints= array_merge($dataPoints, $new_data);
}
}
else
{
echo '<script>alert("Unable to load GraphModel");</script>';
}
编辑:刚刚尝试更改为 while($row = mysqli_fetch_assoc($result)) 但无法从 canvasjs 中显示的值我在没有数据库数据的情况下使用的数组的默认值如下所示
$dataPoints = array(
array("label"=> "Education", "y"=> 284935),
array("label"=> "Entertainment", "y"=> 256548),
array("label"=> "Lifestyle", "y"=> 245214),
array("label"=> "Business", "y"=> 233464),
array("label"=> "Music & Audio", "y"=> 200285),
array("label"=> "Personalization", "y"=> 194422),
array("label"=> "Tools", "y"=> 180337),
array("label"=> "Books & Reference", "y"=> 172340),
array("label"=> "Travel & Local", "y"=> 118187),
array("label"=> "Puzzle", "y"=> 107530)
);
我的错误来自https://canvasjs.com/assets/script/canvasjs.min.js
canvasjs.min.js:208 Uncaught TypeError: Cannot read property 'x' of undefined
at p._processMultiseriesPlotUnit (canvasjs.min.js:208)
at p._processData (canvasjs.min.js:206)
at p.setLayout (canvasjs.min.js:188)
at p.render (canvasjs.min.js:201)
at window.onload (index.php:104)
牛魔王的故事