1 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
您應(yīng)該將 import js 放在從 js 調(diào)用的函數(shù)的頂部。所以最簡(jiǎn)單的方法是放在<script type="text/javascript" src="{{ asset('js/Chart.js') }}"></script>標(biāo)題中?;蛘叻旁陧撃_但在上面new Chart(ctx,{})。以下是示例工作代碼段:
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/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>
- 1 回答
- 0 關(guān)注
- 183 瀏覽
添加回答
舉報(bào)