KoolReport's Forum

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

Error producing chart when part of a drilldown #546

Open Alex Chartier opened this topic on on Dec 5, 2018 - 2 comments

Alex Chartier commented on Dec 5, 2018

I have a chart that when I process it in the view by itself renders just fine. Here is the code:

					ColumnChart::create(array(
						"dataSource"=>$byEvent,
						"title"=>"All Events",
						"columns"=>array(
							"title",
							"amount"=>array("label"=>"Amount Collected", "type"=>"number", "prefix"=>"$", 
								"annotation"=>function($row) {
									return "$".number_format($row['amount']);
								}),
							)
					));

Now when I place this same chart inside a drilldown I get an error: Call to a member function countData() on null at libraries/koolreport/packages/chartjs/Chart.php:178

Here is the code as a drilldown:

    DrillDown::create(array(
    	"name"=>"eventDrillDown",
    	"title"=>"Event Transaction Report",
    	"levels"=>array(
    		array(
    			"Title"=>"All Events",
    			"content"=>function($params, $scope) {
					ColumnChart::create(array(
						"dataSource"=>$byEvent,
						"title"=>"All Events",
						"columns"=>array(
							"title",
							"amount"=>array("label"=>"Amount Collected", "type"=>"number", "prefix"=>"$", 
								"annotation"=>function($row) {
									return "$".number_format($row['amount']);
								}),
							)
					));
					
				}
    		))
    ))	

Any ideas of what I am doing wrong here?

KoolReport commented on Dec 5, 2018

The problem is the variable $byEvent is not available in the function containing the ColumnChart, you need to do this:

"content"=>function($params,$scope) use ($byEvent) {
    ...
}
Alex Chartier commented on Dec 5, 2018

Yes, that works, Thank you.

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
solved

None