0

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]
Manmeet
  • 39
  • 3
  • 1
    Please post CODE in a [mcve] instead of PICTURES of code – mplungjan Mar 27 '20 at 10:32
  • @mplungjan i have attached the pictures of data only incase someone needs while solving the issue. – Manmeet Mar 27 '20 at 10:34
  • @Manmeet : real code instead of screenshots is required to play around with your use case and catch the bug. So if you need someone to make such attempt you're suppoesd to share your code along with input data (obfuscated if you need to conceal it) or even more preferably, executable live snippet. However, considering your [habit](https://stackoverflow.com/q/60652109/11299053) to post images instead of code and accept rate of ***zero*** I doubt someone would do. – Yevhen Horbunkov Mar 27 '20 at 10:42

0 Answers0