I am currently working with Chart.js and have a JavaScript array containing values that look like this:
var obj = JSON.parse('{"0":"8.4113","2":"9.5231","3":"9.0655","4":"7.8400"}');
I am passing the "obj" array to my Chart.js, filling out the bars successfully:
var barChartData = {
labels : obj1,
datasets : [
{
fillColor: "rgba(151,187,205,0.5)",
strokeColor: "rgba(151,187,205,0.8)",
highlightFill: "rgba(151,187,205,0.75)",
highlightStroke: "rgba(151,187,205,1)",
data : obj
}
]
}
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx).Bar(barChartData, {
responsive : true
});
}
</script>
However, there is a second array named "obj1" which contains label names for the chart as follows:
var obj1 = JSON.parse('{"0":"name1","2":"name2","3":"name3","4":"name4"}');
Despite having the label names in the "obj1" array, the labels are still empty on the chart. I am uncertain why this array is not working as expected compared to the data array.