Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lightning Component:
- <aura:component controller="Test">
- <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
- <div class ="card">
- <div class="card-heading context-dashboard">
- Report View
- </div>
- <div class="card-detail">
- <div id="chart"></div>
- </div>
- </div>
- ({
- doInit : function(component, event, helper) {
- var action = component.get("c.runReport");
- action.setCallback(this,function(response){
- var state = response.getState();
- if(state === "SUCCESS"){
- var reportData = JSON.parse(response.getReturnValue());
- console.log ("Return value" + JSON.stringify(response.getReturnValue()));
- var returnData = [];
- for(var i=0, j= reportData.groupingsDown.groupings.lenght; i<j; i++){
- var label = reportData.groupingsDown.groupings[i].label;
- var Key = reportData.groupingsDown.groupings[i].Key;
- var value= reportData.factMap[Key + '!T'].aggregates[0].value;
- returnData.push([label,value]);
- }
- var chart = c3.generate ({
- bindto :'#chart',
- data:{
- coloumns: returnData,
- type: 'pie'
- }
- });
- }
- });
- $A.enqueueAction(action);
- }
- @AuraEnabled
- public static String runReport(){
- Report rep = [SELECT Id, DeveloperName FROM Report where DeveloperName = 'Case' LIMIT 1];
- Reports.ReportResults results = Reports.ReportManager.runReport(rep.Id,true);
- return JSON.serialize(results);
- }
Add Comment
Please, Sign In to add comment