1

I have manged to collect all required data but not able to parse it into the list so that i can pass my data into a chart. for now i have added debug data in to chart as static to relate this chart with debug, but i wants to pass these value dynamically and for that i should have map/wrapper class but i am not able to assign the data into it which method i need to use to collect the required data to show in below chart code.can anyone please help me to do this.

Please find my code,debug, chart code.

Controller:

Reports.reportResults results = Reports.ReportManager.runReport(reportId,false);
        Reports.ReportMetadata rm = results.getReportMetadata();
        //get report name
        reportName1 = rm.getName();
        system.debug('*****reportName:'+reportName);
        //get factMap
        Map<String,Reports.ReportFact> factMap = new Map<String,Reports.ReportFact>();
        Map<String,Reports.ReportFactWithSummaries> summaryMap = new Map<String,Reports.ReportFactWithSummaries>();
        factMap = results.getfactMap();

        System.debug('***getfactMap:'+factMap);

        List<Reports.ReportFact> countList = new List<Reports.ReportFact>();
        for(Reports.ReportFact data:factMap.values())
        {
          System.debug('--->'+data);
        }

        Reports.Dimension dim = results.getGroupingsDown();
        List<Reports.GroupingValue> groupingValList = dim.getGroupings();
        for(Reports.GroupingValue grp1 : groupingValList)
        {
        System.debug('**dim**'+grp1);
        }

Debug:

DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=28, value=28]), key=0!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=10, value=10]), key=0_0!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=4, value=4]), key=1!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=18, value=18]), key=0_1!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=20, value=20]), key=2!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=60, value=60]), key=T!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=8, value=8]), key=3!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=20, value=20]), key=2_0!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=4, value=4]), key=1_0!T]
DEBUG|[56]|DEBUG|--->Reports.ReportFactWithSummaries[aggregates=(Reports.SummaryValue[label=8, value=8]), key=3_0!T]
DEBUG|[65]|DEBUG|**dim**Reports.GroupingValue[groupings=(Reports.GroupingValue[groupings=null, key=0_0, label=Bristol, value=Bristol], Reports.GroupingValue[groupings=null, key=0_1, label=London, value=London]), key=0, label=Dep1, value=Dep1]
DEBUG|[65]|DEBUG|**dim**Reports.GroupingValue[groupings=(Reports.GroupingValue[groupings=null, key=1_0, label=Bristol, value=Bristol]), key=1, label=Dep2, value=Dep2]
DEBUG|[65]|DEBUG|**dim**Reports.GroupingValue[groupings=(Reports.GroupingValue[groupings=null, key=2_0, label=Cambridge, value=Cambridge]), key=2, label=Dep3, value=Dep3]
DEBUG|[65]|DEBUG|**dim**Reports.GroupingValue[groupings=(Reports.GroupingValue[groupings=null, key=3_0, label=London, value=London]), key=3, label=Dep4, value=Dep4]

Chart Code:

  var config1 = {
        type: 'line',
        data: {
            labels: ["","Dep1", "Dep2", "Dep3", "Dep4"],
            datasets: [{
                label: "Bristol",
                borderColor: window.chartColors.red,
                backgroundColor: window.chartColors.red,
                data: [ 0,10,4,0,0],
                fill: false,
            }, {
                label: "London",
                borderColor: window.chartColors.blue,
                backgroundColor: window.chartColors.blue,
                data: [ 0,18,0,0,8],
                fill: false,
            },{
                label: "Cambridge",
                borderColor: window.chartColors.yellow,
                backgroundColor: window.chartColors.yellow,
                data: [0,0,0,20,0],
                fill: false,
            }]
        },

1 Answer 1

0

What you need to do is collect the data in string and then pass it to respective properties of chart.

For example labels property of chart needs values as ["","Dep1", "Dep2", "Dep3", "Dep4"],

To generate this string you can loop through report data and construct desiger string like this:

String lbl = '';
Reports.Dimension dim = results.getGroupingsDown();
List<Reports.GroupingValue> groupingValList = dim.getGroupings();
for(Reports.GroupingValue grp1 : groupingValList)
{
    System.debug('**dim**'+grp1);
    lbl += '"'+groupingVal.getLabel()+ '",';
}
lbl = '[' + lbl + ']';

And then you can send this lbl string to JS and use it in chart .

If you are not sure how to pass value from controler to JS then refer this post.

Pass a string variable from controller into the Javascript function

Note you can optimize your code by using maps & lists.

4
  • Thanks @Atul, it worked. One more thing, is it possible to create the var config1's "data part" in controller itself and then pass the whole "data part" into javascripts config1 data: . i wanted to create below part in my controller: data: { labels: ["","Dep1", "Dep2", "Dep3", "Dep4"], datasets: [{ label: "Bristol", borderColor: window.chartColors.red, backgroundColor: window.chartColors.red, data: [ 0,10,4,0,0], fill: false, }
    – Sharma_raj
    Apr 8, 2017 at 16:56
  • yes, sure you can do that. The point that we should know is our controller executes first and then it can pass any string (it can be js variable or even complete JS code along with HTML) to browser. Then browser runs JS code show us output. Apr 10, 2017 at 3:27
  • Could you please help me with some examples so that i could try with them.
    – Sharma_raj
    Apr 16, 2017 at 9:50
  • Did you check the link that i gave above? its good example . Apr 17, 2017 at 10:11

You must log in to answer this question.

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