0
I’m following the documentation Chats.js to implement graphics in my code the structure of my HTML is very simple
<html>
<head>
<script type="text/javascript" src="./chart.js"></script> //Esse eu baixei através da documentação deles
<script type="text/javascript" src="./index.js"></script>
</head>
<body>
<canvas id="myChart" width="400" height="400"></canvas>
</body>
</html>
And in my javascript index.js is as follows
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
But when I run the code in my browser nothing happens, when inspecting the elements with the browser console and go in the file index.js I see the following error message Uncaught ReferenceError: Chart is not defined
, in my view the import is correct as the Chart.js file is being imported, I am doing something wrong?
Apparently the error is that you used the css import tag (<link>) instead of the javascript import tag (<script>).
– Benilson
@Benilson
– Fábio Santos