我开始开发我的第一个网站。当我尝试在Brackets中实现chart.js时,我总是得到“ReferenceError:”我的Firefox控制台中没有定义图表。如果我在JSFiddle中复制它,它可以工作。感谢您的帮助!
<head>
</head>
<body>
<script src="js/jquery.js"></script>`
<script scr="Chart.min.js"> </script> `
<canvas id="canvas" width="400" height="400"></canvas>
<script>
var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
data : [65,59,90,81,56,55,40]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
data : [28,48,40,19,96,27,100]
}
]
}
var ctx = $("#canvas")[0].getContext("2d");
var TestChart = new Chart(ctx).Bar(data);
new Chart(ctx).Bar(data);
</script>
</body>
答案 0 :(得分:1)
您的代码中有拼写错误:
<script scr="Chart.min.js"></script>
应该是:
<script src="Chart.min.js"></script>
尝试更改您的代码:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js">
</script>
</head>
<body>
`
<canvas id="canvas" width="400" height="400"></canvas>
<script>
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,1)",
data: [65, 59, 90, 81, 56, 55, 40]
}, {
fillColor: "rgba(151,187,205,0.5)",
strokeColor: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 96, 27, 100]
}]
}
var ctx = $("#canvas")[0].getContext("2d");
var TestChart = new Chart(ctx).Bar(data);
new Chart(ctx).Bar(data);
</script>
</body>
</html>