亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Chartjs - Laravel 5.8 未定義未捕獲的參考錯誤圖表

Chartjs - Laravel 5.8 未定義未捕獲的參考錯誤圖表

PHP
ABOUTYOU 2022-06-17 17:10:39
在我的 laravel 項目中,我使用的是 adminlte 儀表板。我也在 adminlte 儀表板中使用 chartjs。Uncaught ReferenceError: Chart is not defined發生錯誤。我嘗試了很多解決方案,但錯誤仍然相同。發生了什么問題以及如何解決這個問題?我在 chartjs 文檔中添加了代碼示例:但這不起作用;                <canvas id="timechart" width="800px" height="400px"></canvas>                <script>                    var ctx = document.getElementById('timechart').getContext('2d');                        var chart = new Chart(ctx, {                            // The type of chart we want to create                            type: 'line',                            // The data for our dataset                            data: {                                labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],                                datasets: [{                                    label: 'My First dataset',                                    backgroundColor: 'rgb(255, 99, 132)',                                    borderColor: 'rgb(255, 99, 132)',                                    data: [0, 10, 5, 2, 20, 30, 45]                                }]                            },                            // Configuration options go here                            options: {}                        });                </script>在主布局中添加 chartjs:<script type="text/javascript" src="{{ asset('js/Chart.js') }}"></script>
查看完整描述

1 回答

?
HUX布斯

TA貢獻1876條經驗 獲得超6個贊

您應該將 import js 放在從 js 調用的函數的頂部。所以最簡單的方法是放在<script type="text/javascript" src="{{ asset('js/Chart.js') }}"></script>標題中?;蛘叻旁陧撃_但在上面new Chart(ctx,{})。以下是示例工作代碼段:


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>


<canvas id="timechart" width="800px" height="400px"></canvas>

                <script>

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

                        var chart = new Chart(ctx, {

                            // The type of chart we want to create

                            type: 'line',

                            // The data for our dataset

                            data: {

                                labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],

                                datasets: [{

                                    label: 'My First dataset',

                                    backgroundColor: 'rgb(255, 99, 132)',

                                    borderColor: 'rgb(255, 99, 132)',

                                    data: [0, 10, 5, 2, 20, 30, 45]

                                }]

                            },

                            // Configuration options go here

                            options: {}

                        });

                </script>


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 170 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號