Skip to content

Instantly share code, notes, and snippets.

@unclebay143
Created November 15, 2021 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unclebay143/b9a044c09954f176b746df2ec0c9bf5c to your computer and use it in GitHub Desktop.
Save unclebay143/b9a044c09954f176b746df2ec0c9bf5c to your computer and use it in GitHub Desktop.
Chart.js - Bar Chart Code
// 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