admin管理员组文章数量:1389881
I've installed chart.js
using npm by : npm install chart.js --save-dev
, in "resources/assets/js/bootstrap.js"
I refer to it by:
require('chart.js');
Then in my console npm run dev
and finally it's successfully piled in "public/js/app.js"
, however when I try to use it in my view as follow
<script src="/js/app.js"></script><script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
......... </script>
the browser returns
Uncaught ReferenceError: Chart is not defined.
How e it's declared in app.js
and can't refer to it ?
Thanks in advance.
I've installed chart.js
using npm by : npm install chart.js --save-dev
, in "resources/assets/js/bootstrap.js"
I refer to it by:
require('chart.js');
Then in my console npm run dev
and finally it's successfully piled in "public/js/app.js"
, however when I try to use it in my view as follow
<script src="/js/app.js"></script><script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
......... </script>
the browser returns
Uncaught ReferenceError: Chart is not defined.
How e it's declared in app.js
and can't refer to it ?
Thanks in advance.
- Maybe you're using strict "use strict" mode? – DevK Commented Mar 29, 2017 at 15:26
2 Answers
Reset to default 2If you're using es6 you might need to change the way you require it.
from the docs: http://www.chartjs/docs/
// Using CommonJS
var Chart = require('chart.js')
var myChart = new Chart({...})
// ES6
import Chart from 'chart.js'
let myChart = new Chart({...})
// Using requirejs
require(['path/to/Chartjs'], function(Chart){
var myChart = new Chart({...})
})
If you look in app.js, is it wrapped in a function? It sounds like it's not part of the global namespace, despite being present in app.js.
本文标签: javascriptUncaught ReferenceError Chart is not definedStack Overflow
版权声明:本文标题:javascript - Uncaught ReferenceError: Chart is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744576603a2613663.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论