猿问

Chartjs 与 PHP 问题(意外令牌)

我有下面给出的代码


<script type="text/javascript">

    var ctx = document.getElementById("myChart").getContext('2d');

    var myChart = new Chart(ctx, {

        type: 'bar',

        data: {

            labels: ["A1", "B1", "C1"],

            datasets: [{

                label: '',

                datasets:[

                    <?php 

                    $jumlah_A1 = mysqli_query($koneksi,"select * from mesin where LokasiMesin='A1'");

                    echo mysqli_num_rows($jumlah_A1);

                    ?>, 

                    <?php 

                    $jumlah_B1 = mysqli_query($koneksi,"select * from mesin where LokasiMesin='B1'");

                    echo mysqli_num_rows($jumlah_B1);

                    ?>, 

                    <?php 

                    $jumlah_C1 = mysqli_query($koneksi,"select * from mesin where LokasiMesin='C1'");

                    echo mysqli_num_rows($jumlah_C1);

                    ?>,

                    backgroundColor: [ <!-- Error on here -->

                    'rgba(255, 99, 132, 0.2)',

                    'rgba(54, 162, 235, 0.2)',

                    'rgba(255, 206, 86, 0.2)'

                    ],

                    borderColor: [

                    'rgba(255,99,132,1)',

                    'rgba(54, 162, 235, 1)',

                    'rgba(255, 206, 86, 1)'

                    ],

                    borderWidth: 1;

                ]

            }]

        },

        options: {

            scales: {

                yAxes: [{

                    ticks: {

                        beginAtZero:true

                    }

                }]

            }

        }

    });

浏览器控制台上的错误是“意外令牌:”(标记在代码行上),但是当我按照 Chart.js 的文档进行操作时,文档可能与我正在做的相同。


这是图片:

有什么帮助解决这个问题吗?



qq_遁去的一_1
浏览 88回答 1
1回答

阿晨1998

您的数据集括号上有一些错误var myChart = new Chart(ctx, {&nbsp; &nbsp; &nbsp; &nbsp; type: 'bar',&nbsp; &nbsp; &nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; labels: ["A1", "B1", "C1"],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datasets: [{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: '',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datasets:[&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $jumlah_A1 = mysqli_query($koneksi,"select * from mesin where LokasiMesin='A1'");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo mysqli_num_rows($jumlah_A1);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?>,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $jumlah_B1 = mysqli_query($koneksi,"select * from mesin where LokasiMesin='B1'");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo mysqli_num_rows($jumlah_B1);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?>,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $jumlah_C1 = mysqli_query($koneksi,"select * from mesin where LokasiMesin='C1'");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo mysqli_num_rows($jumlah_C1);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?>], <!-- Bracket here-->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; backgroundColor: [&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'rgba(255, 99, 132, 0.2)',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'rgba(54, 162, 235, 0.2)',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'rgba(255, 206, 86, 0.2)'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderColor: [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'rgba(255,99,132,1)',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'rgba(54, 162, 235, 1)',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'rgba(255, 206, 86, 1)'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderWidth: 1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }]&nbsp; &nbsp; &nbsp; &nbsp; }
随时随地看视频慕课网APP
我要回答