Created
November 15, 2021 11:35
-
-
Save unclebay143/b9a044c09954f176b746df2ec0c9bf5c to your computer and use it in GitHub Desktop.
Chart.js - Bar Chart Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Grab the bar chart canvas | |
const barChartContext = document | |
.getElementById('js-bar-chart') | |
.getContext('2d'); | |
// Chart configuration | |
const config = { | |
type: 'bar', | |
data: { | |
// Chart data | |
labels: ['JAVASCRIPT', 'HTML/CSS', 'SQL', 'PYTHON', 'JAVA'], | |
datasets: [ | |
{ | |
data: [67.7, 63.1, 54.7, 44.1, 40.2], | |
label: 'Programming languages votes', | |
backgroundColor: ['yellow', 'blue', 'brown', 'purple', 'indigo'], | |
borderWidth: 0.3, | |
borderColor: 'black', | |
}, | |
], | |
}, | |
options: { | |
responsive: true, | |
scales: { | |
y: { | |
ticks: { | |
callback: function (value) { | |
return value + '%'; | |
}, | |
}, | |
}, | |
}, | |
}, | |
}; | |
// Creating a new chart instance | |
const newBarChart = new Chart(barChartContext, config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment