KoolReport's Forum

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

Export PDF / no data available in chart #3185

Open Martin opened this topic on on Nov 1, 2023 - 9 comments

Martin commented on Nov 1, 2023

Hi,

I'm trying to make an export pdf with a chart but in the result pdf file , there is only text and some features and instead of my chart this message [no data available in chart]

What's the problem ?

I'm in localhost , linux. . Regards.

Sebastian Morales commented on Nov 2, 2023

If your report data depends on input values pls put your Export button (use button, not a tag) inside a form tag so that when it's clicked the form data is submitted as well for your report to show non-empty data. In any case pls post your report setup, web view and pdf view code for us to check it for you.

Martin commented on Nov 2, 2023

Hi,

The problem is i use a php to populate an array ( with all datas for the chart ) , and that php is call from jquery. So i can't use the submit form. Regards.

Martin commented on Nov 2, 2023

Hi again,

Is there a way to call the export pdf when chart is generate for the html page ?

Regards

Sebastian Morales commented on Nov 2, 2023

Pls post the code of your web and pdf view files?

Martin commented on Nov 2, 2023

Is there a way to call the export pdf when chart is generate for the html page ?

Regards

Martin commented on Nov 2, 2023

Courbe_predic.php :

<?php

require_once "CourbePredic.php";
$CourbePredic = new CourbePredic(array(
    "data"=>$data_source,));

$CourbePredic->run()->render();
?> 

CourbePredic.php :

<?php
require_once "koolreport/core/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;

class CourbePredic extends \koolreport\KoolReport
{
	 use \koolreport\export\Exportable;
	 
    public function settings()
    {
    	  //include ("ext/config_report_adm.php");
    	  
        return array(
            "dataSources"=>array(
                "mydata"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "data"=>$this->params["data"],
                    "dataFormat"=>"associate",
                )
            )
        );
    }

    public function setup()
    {
        $this->src('mydata')
        ->pipe(new Sort(array("date"=>"asc",))) 
        ->pipe($this->dataStore('courbe_predic'));

    }
    
    
}
?> 

CourbePredic.view.php :

<?php 
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;
?>

<?php

 
    LineChart::create(array(
    "title"=>"",
    "dataSource"=>$this->dataStore('courbe_predic'),
    "options"=>array(
        "curveType"=>"function"
    ),
        "columns"=>array(
            "date",
            "prod"=>array(
                "label"=>"Production",
                "type"=>"number",
                "prefix"=>"W"
            ),
            "predic"=>array(
                "label"=>"Prevision",
                "type"=>"number",
                "prefix"=>"W"
            ),
        )
));    
    
?>

Export.php :

<?php 

require_once "report/CourbePredic.php";
$report = new CourbePredic;

$report->run()
->export('CourbePredicPdf')
->settings([
    "useLocalTempFolder" => true,
])
->pdf(array(
    "format"=>"A4",
    "orientation"=>"portrait",
    //"zoom"=>2
))
->toBrowser("courbe_predic.pdf");


?>
KoolReport commented on Nov 3, 2023

It is because in the the Export.php, the CourbePredic does not not have data like you do in Courbe_predic.php

Martin commented on Nov 10, 2023

Hi, Ok thanks. But is there a way to generate pdf in the same time with the view ? Best regards

David Winterburn commented on Nov 13, 2023

In your Export.php, you have to create the report with the same parameters as in your web view since your datassource is populated with "data"=>$this->params["data"]:

//Export.php
require_once "report/CourbePredic.php";
$CourbePredic = new CourbePredic(array(
    "data"=>$data_source,)); 

$report->run()
->export('CourbePredicPdf')
->settings([
    "useLocalTempFolder" => true,
])
->pdf(array(
    "format"=>"A4",
    "orientation"=>"portrait",
    //"zoom"=>2
))
->toBrowser("courbe_predic.pdf"); 

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