How To Auto Create Pdf Using Highchart Graphs
I am using yii framework 1.14 with php on centos 5. I have designed a view that contains 4 graphs created using highcharts. i want to export this page to pdf from my controller/act
Solution 1:
I have installed phantomjs
in my controller, created an array and encoded it with json with output to file. Then used phantomjs
to convert it to image. See the code below.
I am using Yii
and have highcharts
located in the extensions folder which contains everything I need. I had to download and place batik
in that directory.
$json = json_encode(array(
"chart"=>array(
"type"=>'column',
"width"=>1000,
"height"=>350
),
"title"=>array(
"text"=>$title[$i]
),
"xAxis"=>array(
"categories"=>$cat,
"labels"=>array(
"rotation"=>$rotation,
"align"=>'left',
"style"=>array(
"fontSize"=>'8px',
"fontFamily"=>'Verdana, sans-serif',
"width"=>"75px"
)
)
),
"yAxis"=>array(
"min"=>0,
"max"=>100,
"title"=>array(
"text"=>'% COMPLETE'
),
"tickInterval"=>10
),
"plotOptions"=>array(
"column"=>array(
"pointPadding"=> 0.2,
"borderWidth"=> 0
)
),
"legend"=>array(
"enabled"=>true,
"verticalAlign"=>'middle',
"align"=>'right',
//"floating"=> true
),
"credits"=>array(
"enabled"=> false
),
"series"=>array(
array(
'name'=>'Planned',
'data'=>$planned,
'color'=> "rgb(91,155,213)"
),
array(
"name"=>'Actual',
"data"=>$complete,
"color"=>'rgb(237,125,49)'
)
)
));
$file = "protected/extensions/highcharts/exporting-server/php/php-batik/temp/$i.json";
// Write the contents back to the file
file_put_contents($file, $json);
// generates images to use for weekly status report
shell_exec("/usr/local/bin/phantomjs protected/extensions/highcharts/exporting-server/phantomjs/highcharts-convert.js -infile protected/extensions/highcharts/exporting-server/php/php-batik/temp/${i}.json -outfile images/$i.png -constr Chart");
Post a Comment for "How To Auto Create Pdf Using Highchart Graphs"