javascript Morris.js未捕获类型错误:无法读取未定义的属性(读取"length")

nwwlzxa7  于 2023-01-04  发布在  Java
关注(0)|答案(1)|浏览(133)

我是新的php和javascript,我正在做一个项目,我需要在我的网页中实现图形,但我得到这个错误morris. min. js:6 Uncaught TypeError: Cannot read properties of undefined (reading 'length'),我无法找到解决方案

html code
<!DOCTYPE html><html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><link rel="stylesheet" href="../Css/AdminDashboard.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">2 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>3 <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>4 <script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js">
</script>
</head>
<body><div class="bookingsGraph">
<div id="chart">
</div>
</div>
</body>
</html>
<script>
    Morris.Line({
        element: 'chart',
        data: [<?php echo $chart_data; ?>],
        xkey: 'date',
        ykey: ['bookings'],
        labels: ['Bookings'],
        // hideHover: 'auto',
        // stacked: true

    });
</script>

php代码

<?php
$connect = mysqli_connect("localhost", "root", "", "movietime");
$query = "SELECT COUNT(BookingId),BookingDate
FROM bookings
WHERE BookingDate='2019/12/13'";
$result = mysqli_query($connect, $query);
$chart_data = '';
while($row = mysqli_fetch_array($result))
{

  $chart_data .= "{ date:'".$row["BookingDate"]."', bookings:".$row["COUNT(BookingId)"]."}, ";
}
 $chart_data = substr($chart_data, 0, -2);
?>

完全误差

morris.min.js:6 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at c.<anonymous> (morris.min.js:6:4567)
    at c.<anonymous> (morris.min.js:6:4834)
    at d.setData (morris.min.js:6:4865)
    at c.d [as constructor] (morris.min.js:6:1739)
    at new c (morris.min.js:6:13513)
    at Object.c [as Line] (morris.min.js:6:13534)
    at AdminDashboard.php:114:12

我试过了

Morris.Line({
    element: 'chart',
    data: [{date:'2019/12/13',bookings:'6'}],
    xkey: 'date',
    ykey: ['bookings'],
    labels: ['Bookings'],
    // hideHover: 'auto',
    // stacked: true

});
w8f9ii69

w8f9ii691#

需要一个名为“length”的值

Morris.Line({
    element: 'chart',
    data: [{date:'2019/12/13',bookings:'6'}],
    xkey: 'date',
    ykey: ['bookings'],
    labels: ['Bookings'],
    length: 200,  <-------------- try putting this in
    // hideHover: 'auto',

我不知道它为什么要这样做,但是给它一个名为length的值可能会让你通过这个问题。一旦代码运行,Length将变得不言自明。我希望这会有所帮助。

相关问题