I have a ColumnChart witch can be exported to a pdf. It works fine. But I have a similar Chart, where I always get a format error for the exported pdf. The rendering of the chart on my website works fine for both charts.
I found out where the problem is: if I remove the variable $data['DateMonthNameDE'] from the hAxis, Also the working diagram is no longer exported.
But I don't know why this happen. For me it looks like a bug of the exporting system.
I'm using: Symfony 6 php8.0.8 koolreport/core: 6.0.1 koolreport/export: 5.2.0 koolreport/pro: 6.0.6
The working code:
//JobsYearMonth.php
namespace App\Reports\Jobs;
use koolreport\processes\CalculatedColumn;
class JobsYearMonths extends \koolreport\KoolReport
{
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
use \koolreport\export\Exportable;
use \koolreport\excel\ExcelExportable;
use \koolreport\excel\CSVExportable;
...
protected function setup()
{
$this->src("warehouse_datasource")
->query("
SELECT dim.tDate.DateMonth, COUNT(fact.tJob.JobID) AS amount, dim.tDate.DateYear, dim.tDate.DateMonthNameDE
FROM fact.tJob INNER JOIN
dim.tDate ON fact.tJob.JobCreatedDateID = dim.tDate.DateID
WHERE (fact.tJob.JobCompanyID = :CompanySiteCompanyID
AND ... )
)
GROUP BY dim.tDate.DateYear, dim.tDate.DateMonthNameDE, dim.tDate.DateMonth
ORDER BY dim.tDate.DateYear, dim.tDate.DateMonth
")
->params(...)
->pipe(new CalculatedColumn(array(
"month_year"=>array(
"exp"=>function($data){
return $data["DateMonthNameDE"].", ".$data["DateYear"];
},
"type"=>"string",
)
)))
->pipe($this->dataStore("jobs_created"));
//JobsYearMonthsPDF.view.php
<?php
use koolreport\widgets\google\ColumnChart;
?>
<!DOCTYPE html>
<html>
<body style="margin:1in">
...
<?php
ColumnChart::create(array(
"title"=>"Jobs erstellt",
"dataSource"=>$this->dataStore("jobs_created"),
"height" => "500px",
"columns"=>array(
"month_year"=>array(
"label"=>"Monat"
),
"amount"=>array(
"label"=>"Jobs",
"type"=>"number",
)
),
"options" => array(
"backgroundColor"=>"transparent",
"chartArea"=> array(
"top" => 55,
),
"hAxis" => array(
"slantedText" => true,
"slantedTextAngle" => 60,
),
)
))
?>
</body>
</html>
After I remove the variable $data["DateMonthNameDE"] it doesn't export anymore:
...
->pipe(new CalculatedColumn(array(
"month_year"=>array(
"exp"=>function($data){
return ", ".$data["DateYear"];
},
"type"=>"string",
)
)))
...
What I really want is a similar chart witch shows me the Quarter columns instead of the Months:
...
->query( ... // just a little different query)
...
->pipe(new CalculatedColumn(array(
"quarter_year"=>array(
"exp"=>function($data){
return $data["DateQuarter"].". Quartal ".$data["DateYear"];
},
"type"=>"string",
)
)))
...
Could you explain to me why this hAxis makes such problems? Thanks :)