为了账号安全,请及时绑定邮箱和手机立即绑定

PHP Canvas 无法显示

PHP Canvas 无法显示

PHP
FFIVE 2021-10-22 13:27:31
$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.jscanvasjs.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)
查看完整描述

1 回答

?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

我发现了问题所在。由于我没有将 $new_data 设置为数组,因此 $dataPoints 无法找到要显示的数组 ID。在这里我如何修复它


<?php

        $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);

        $dataPoints = array();

        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, array($new_data));   

                print_r($dataPoints);               

            };

        }

        else

        {

            echo '<script>alert("Unable to load GraphModel");</script>';

        }


    ?>


查看完整回答
反对 回复 2021-10-22
  • 1 回答
  • 0 关注
  • 162 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信