KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Integrating an existing Google report #1518

Open Richb201 opened this topic on on Jul 8, 2020 - 3 comments

Richb201 commented on Jul 8, 2020

Hi. I have been using a Google org chart in my app for a few years. Here is the view that creates it. What is the easiest way to use this existing chart so that it appears in my KoolReport?

<head>
    <title>Substantiator</title>
	<meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

<body>
<html>
<head><br>

    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

    <script>
        google.charts.load('current', {packages:['orgchart']});
        google.charts.setOnLoadCallback(drawChart);


    function drawChart() {
        var jsonData = $.ajax({
        type : "GET",
            url: "<?php echo base_url(); ?>" + "index.php/Configure/snd_json",
           dataType: "json",
         //  jsonp: false,
            cache: false,
            dataSrc: '',
            success: function(jsonData)
                {
              // var jD = JQuery.parseJSON(jsonData);

                var data = new google.visualization.DataTable();
                data.addColumn('string', 'employee_email');
                data.addColumn('string', 'manager_email');
                data.addColumn('string', 'ToolTip');
               for ( var i=0, ien=jsonData.length ; i<ien ; i++ ) {
                    var rowArr= [jsonData[i].employee_email,jsonData[i].manager_email,jsonData[i].employee_title];
                    data.addRow(rowArr);
                     }

                var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
                // Draw the chart, setting the allowHtml option to true for the tooltips.
                chart.draw(data, {});
                },
            error:
               function (jqXHR, textStatus, errorThrown) {
                alert('error');
                   // Request failed. Show error message to user.
                   // errorThrown has error message, or "timeout" in case of timeout.


               },

            async: false,
            timeout: 10000,

        }).responseText;


        }


    </script>
</head>


<!--Div that will hold the pie chart-->
<br><br><br>


<div id="chart_div"></div>


</body>
</html>

KoolReport commented on Jul 9, 2020

You can do:

<?php
\koolreport\widgets\google\OrgChart::create([
    "dataSource"=>[
        ["Name"=>"Mike","Manager"=>"","Tooltip"=>"President"],
        ["Name"=>"Jim","Manager"=>"Mike","Tooltip"=>"VP"],
        ["Name"=>"Alice","Manager"=>"Mike","Tooltip"=>""],
        ["Name"=>"Bob","Manager"=>"Jim","Tooltip"=>""],
        ["Name"=>"Carol","Manager"=>"Bob","Tooltip"=>""],
    ],
]);
?>
Richb201 commented on Jul 9, 2020

I copied you code exactly as above into MyReport.view.php. This is what I got:

As you can see the Organizational chart is completely blank.

Richb201 commented on Oct 4, 2020

I got it to appear. Now I just need to make sure it is correct. How can I view the data Store so I can see if my sql query is correct? Also, looking at the Google orgchart docs I see that they allow formatting. Is there a way to do this within koolreport?

data.addRows([

  [{v:'Robert', f:'Robert<div style="color:red; font-style:italic">President</div>'},'', 'President'],
  [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President</div>'},'Robert', 'Vice President'],
  ['Alice', 'Robert', ''],
  ['Bob', 'Jim', 'Bob Sponge'],
  ['Carol', 'Bob', '']

]);

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None