Created
June 21, 2017 22:06
-
-
Save laurentmih/8dd46de2c50199c95ec2c2de629a51fa to your computer and use it in GitHub Desktop.
ChartJS categorical bar chart: labels on both axes
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
// 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