HTML
xxxxxxxxxx
1
<canvas id="barChart"></canvas>
CSS
xxxxxxxxxx
1
/* Sorry for using ID for styling :( */
2
#barChart {
3
max-width: 500px;
4
}
5
6
canvas {
7
background-color: rgba(47, 152, 208, 0.1);
8
}
JS
xxxxxxxxxx
1
var ctxB = document.getElementById("barChart").getContext('2d');
2
3
var myBarChart = new Chart(ctxB, {
4
type: 'bar',
5
data: {
6
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
7
datasets: [{
8
label: '# of Votes',
9
data: [12, 19, 3, 5, 2, 3],
10
backgroundColor: [
11
'rgba(255, 99, 132, 0.2)',
12
'rgba(54, 162, 235, 0.2)',
13
'rgba(255, 206, 86, 0.2)',
14
'rgba(75, 192, 192, 0.2)',
15
'rgba(153, 102, 255, 0.2)',
16
'rgba(255, 159, 64, 0.2)'
17
],
18
borderColor: [
19
'rgba(255,99,132,1)',
20
'rgba(54, 162, 235, 1)',
21
'rgba(255, 206, 86, 1)',
22
'rgba(75, 192, 192, 1)',
23
'rgba(153, 102, 255, 1)',
24
'rgba(255, 159, 64, 1)'
25
],
26
borderWidth: 1
27
}]
28
},
29
options: {
30
scales: {
31
yAxes: [{
32
ticks: {
33
beginAtZero: true
34
}
35
}]
36
}
37
}
38
});
39
Console errors: 0