Skip to content

Instantly share code, notes, and snippets.

@laurentmih
Created June 21, 2017 22:06
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 laurentmih/8dd46de2c50199c95ec2c2de629a51fa to your computer and use it in GitHub Desktop.
Save laurentmih/8dd46de2c50199c95ec2c2de629a51fa to your computer and use it in GitHub Desktop.
ChartJS categorical bar chart: labels on both axes
// ChartJS charts
$(document).ready(function(){
// Coding/language barchart
var codingChart = $("#codinglevel");
var codingChartData = {
labels: ["Python ", "Octave/MATLAB ", "JavaScript "],
datasets: [{
data: [2.7, 2, 2],
backgroundColor: ["rgba(255, 99, 132, 0.2)", "rgba(255, 159, 64, 0.2)", "rgba(255, 205, 86, 0.2)"],
borderColor: ["rgb(255, 99, 132)", "rgb(255, 159, 64)", "rgb(255, 205, 86)"],
borderWidth: 1
}]
};
var codingChartOptions = {
maintainAspectRatio: false,
tooltips: {
enabled: false,
},
legend: {
display: false,
},
animation: {
easing: 'easeOutQuint',
},
scales: {
yAxes: [{
ticks: {
},
gridLines: {
drawOnChartArea: false,
drawTicks: false
},
}],
xAxes: [{
ticks: {
beginAtZero:true,
display:true,
callback : function(value) {
if (value == 1)
return 'Novice';
else if (value == 2)
return 'Intermediate';
else if (value == 3)
return 'Advanced';
else if (value == 4)
return 'Expert';
else
return '';
},
max: 4,
}
}]
}
};
var codinglevelchart = new Chart(codingChart, {
type: 'horizontalBar',
data: codingChartData,
options: codingChartOptions
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment