0

Apex Controller

public class TableBookingStatusController {
    
    @AuraEnabled
    public static List<DataSet> getAllTables(){
        List<Table__c> result =  [Select Name, Time_Slot__c from Table__c where IsBooked__c=true];
        List<DataSet> dataSet = new List<DataSet>();
        for(Table__c ar:result){
            String Name =  (String)ar.get('Name') ;
            //Integer total =(Integer)ar.get('cnt'); 
            String TimeSlot=(String)ar.get('Time_Slot__c');
            dataSet.add(new DataSet(Name,TimeSlot));
            
        }
        System.debug('dataSet'+dataSet);
        
        
        return dataSet ;  
    }
}

JS controller

({
    scriptsLoaded : function(component, event, helper) {
        
        var action = component.get("c.getAllTables");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                let val = response.getReturnValue() ;
                var dataset=[];
                var labely=[];
                val.forEach(function(key) {
                    labely.push(key.Name);
                    // dataset.push(key.Name) ; 
                    dataset.push(key.TimeSlot); //Getting a null value in this dataset
                    //console.log(labely);
                    //console.log(key.TimeSlot);
                    console.log(dataset);

                    
                });
                new Chart(document.getElementById("bar-chart"), {
                    type: 'horizontalBar',
                    data: {
                        labels:['10:00','10:30','11:00','11:30','12:00','12:30','1:00','1:30','2:00','2:30','3:00','3:30','4:00','4:30','5:00','5:30','6:00','6:30','7:00','7:30','8:00','8:30','9:00','9:30','10:00'],
                        datasets: [{
                            label: "Time Slot",
                            backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9"],
                            data:dataset
                        }]
                    },
                    
                 
                    options: {
                        scaleShowValues: true,
                        title: {
                            display: true,
                            text: 'Tables Booked'
                        },
                        scales: {
                            xAxes: [{
                                type: 'category',
                                position: 'top',
                                
                                
                            }],
                            yAxes: [{
                                position: 'left',
                                type: 'linear',
                                
                                ticks: {
                                    min: 0,
                                    max: 10,

                                    callback: function(value, index, values) {
                                        //console.log(labely);
                                        return labely[value];
                                    }
                                },
                                
                                // Specific to Horizontal Bar Controller
                                categoryPercentage: 0.8,
                                barPercentage: 0.9,
                                
                                // grid line settings
                                gridLines: {
                                    offsetGridLines: true
                                }
                            }]
                        },
                        
                        
                    }
                });
            }
        });
        $A.enqueueAction(action);
        
    }
})

DataSet controller

public class DataSet {
    
    public DataSet(String name, String timeslot){
            this.Name  = name ; 
            this.TimeSlot = timeslot ;
            //this.count=count;
            system.debug(this.Name + this.TimeSlot);
        }
       
        @AuraEnabled
        //public Integer  count {get;set;}
        public String  Name {get;set;}
        public String  TimeSlot {get;set;}
}
6
  • Please add more specific details about the error you are facing. Also, did you check the apex debug logs if you are getting the data from query or not? Commented Sep 7, 2020 at 8:20
  • @rahulgawale Yes I checked the debug logs, I'm getting the data from query there but in the JS controller I'm getting null in the console for the values in the dataset for TimeSlot Commented Sep 7, 2020 at 8:26
  • Is the Dataset class aura enabled? can you add its source as well? Commented Sep 7, 2020 at 8:27
  • Added the source. The Dataset is a constructor here and we cannot make constructors Aura enabled right? Commented Sep 7, 2020 at 8:34
  • Yes but you need to add it to the class members. Commented Sep 7, 2020 at 8:34

1 Answer 1

0

You need to add @AuraEnabled to all members of the DataSet class.

public class DataSet {
    
    public DataSet(String name, String timeslot){
        this.Name  = name ; 
        this.TimeSlot = timeslot ;
        //this.count=count;
        system.debug(this.Name + this.TimeSlot);
    }
       
    @AuraEnabled
    public String  Name {get;set;}
    @AuraEnabled
    public String  TimeSlot {get;set;}
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .