PHP Canvas 无法显示

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


FFIVE
浏览 163回答 1
1回答

牛魔王的故事

我发现了问题所在。由于我没有将 $new_data 设置为数组,因此 $dataPoints 无法找到要显示的数组 ID。在这里我如何修复它<?php&nbsp; &nbsp; &nbsp; &nbsp; $sql = "SELECT count(order_id) as counti, order_date FROM order_detail GROUP BY order_date ORDER BY order_date DESC";&nbsp; &nbsp; &nbsp; &nbsp; $result = mysqli_query($conn, $sql);&nbsp; &nbsp; &nbsp; &nbsp; $dataPoints = array();&nbsp; &nbsp; &nbsp; &nbsp; if(mysqli_num_rows($result) > 0)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while($row = mysqli_fetch_assoc($result))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $new_data = array("label"=> $row['order_date'], "y"=> $row['counti']);&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $dataPoints = array_merge($dataPoints, array($new_data));&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print_r($dataPoints);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<script>alert("Unable to load GraphModel");</script>';&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ?>
打开App,查看更多内容
随时随地看视频慕课网APP