I am working with Chart JS and the graph data wont show up. I'm pretty sure I followed the proper way of implementing it but the graph data doesn't show up..
This is the data response from the API.
response: {
"users": {
"1": 3,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
"10": 0,
"11": 0,
"12": 0
},
"males": 3,
"females": 0,
"docs": {
"1": 3,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
"10": 0,
"11": 0,
"12": 0
},
"regular": 3,
"contractual": 0
}
and here's how I implement the charts
var userData;
var genderData;
var docsData;
var empStatusData;
$.ajax({
url : dataUrl,
type : 'GET',
success : function(response){
userData = response.users;
genderData = [response.males,response.females];
docsData = response.docs;
empStatusData = [response.regular,response.contractual];
}
})
let chart = document.getElementById('users-chart').getContext('2d');
let popChart = new Chart(chart,{
type : 'bar',
data : {
labels : ['Jan', 'Feb', 'Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
datasets : [{
label: 'User Registrations this year',
data: userData,
backgroundColor: 'rgba(0, 119, 204, 0.3)'
}]
}
});
I only get a blank graph with no data in it. what am I doing wrong here?
Appreciate the help. Thanks everyone.