I have data coming from the Api:
What i am trying to do is getting the count year by year
This is my function for getting the count: The problem I am facing is instead of adding the count to the array its showing that year value as Nan:
Can Anyone please tell me where i went wrong?
getGraphData( data,config) {
debugger;
var account = this.getCallCount();
var year = new Date().getUTCFullYear();
var years = [];
years.push({ type: "Year", key: "1", value: new Date().getUTCFullYear() });
years.push({ type: "Year", key: "2", value: new Date().getUTCFullYear()-1 });
years.push({ type: "Year", key: "3", value: new Date().getUTCFullYear()-2 });
years.push({ type: "Year", key: "4", value: new Date().getUTCFullYear()-3 });
var labels = this.state.results.map(m => m["Profile.Name"]);
var targetTypes = this.state.results.map(m => ({Value: m["Profile.Name"]}));
//targetTypes.push({ type: "Year", key: "NoTarget", value: "Calls" });
var fData = {};
targetTypes.forEach(f => {
fData[f.Value] = { label: f.Value, data: years.map(m => 0) };
});
if (this.state.results !== null) {
for (var c = 0; c < this.state.results.length; c++) {
var call = this.state.results[c];
if (call !== undefined && call !== null) {
var cDate = new Date(call.Last_iPad_Sync_vod__c);
if (cDate != null && (cDate.getFullYear() === year) || (cDate.getFullYear() === year-1) || (cDate.getFullYear() === year-2) || (cDate.getFullYear() === year-3)) {
var targetType = call["Profile.Name"];
if (targetType !== undefined && targetType !== null) {
var actData = fData[targetType];
if (actData !== undefined && actData !== null)
actData.data[cDate.getFullYear()] = actData.data[cDate.getFullYear()] +1 ;
else {
actData = fData["NoTarget"];
actData.data[cDate.getFullYear()] = actData.data[cDate.getFullYear()] + 1 ;
}
}
else {
actData = fData["NoTarget"];
actData.data[cDate.getFullYear()] = actData.data[cDate.getFullYear] + 1;
}
}
}
}
}
}
Input data:
ProfileName Last_iPad_Sync_vod__c
1. MSL 2018-11-26T09:02:04.000+0000
2. Sales 2019-12-05T05:19:30.000+0000
I need the data in array like :
MSl: [0,0,0,0,0,0,0,0,0,0,1,0] //these are months in array i have set their values as 0
Sales: [0,0,0,0,0,0,0,0,0,0,1]