Reputation: 325
I am trying to create a graph in codeigniter and convert it to pdf. For pdf conversion I am using mpdf.
For graph generate I tried several method . including - phpgraphlib,phpmygraph5.0 and also gcharts..
gchart is generating the graph in javascript I guess.. So I tried with phpgraphlib and phpmygraph5 . But the problem I am facing now the graph is generating in the browser. Stuck how to convert it to image and send as data array to my pdf view..
Here is my pdf generation code:
$this->CI->load->library('pdf');
$pdf = $this->CI->pdf->load();
$style = 'assets/pdf/pdf.css';
$stylesheet = file_get_contents( $style);
//$pdf-> $img = file_get_contents($this->graph());
$graph_result['points'] = $points;
$graph_result['profile'] = $profile;
$graph_result['image'] = file_get_contents($this->mygraph());
$content = $this->CI->load->view('pdf/graph_pdf_view', $graph_result, TRUE);
$pdf->WriteHTML($stylesheet,1);
$pdf->WriteHTML($content,2);
$pdf->Output('Graph.pdf', 'I');
Here is generating graph function:
public function graph()
{
//graph library loads.......
include (APPPATH.'libraries/phpgraphlib/phpgraphlib.php');
$graph = new PHPGraphLib(650,200);
$data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033,
"5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024,
"10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036,
"14" => .0028, "15" => .0025);
//print_r($data);
$graph->addData($data);
$graph->setTitle('PPM Per Container');
$graph->setBars(false);
$graph->setLine(true);
$graph->setDataPoints(true);
$graph->setDataPointColor('maroon');
$graph->setDataValues(true);
$graph->setDataValueColor('green');
$graph->setGoalLine(.0025);
$graph->setGoalLineColor('yellow');
$graph->createGraph();
return $graph;
}
When I call graph function from pdf generation function it directy generate graph on the browser.. not goint to the next piece of code in where I load view for pdf.. How can I save this generated graph as an image and only pass that image to pdf view??
Upvotes: 1
Views: 2419
Reputation: 568
It is easy to save the resulting graph as an .png image file, you must see this:
Save phpgraphlib graph as image
According to the documentation, the command is like this:
$graph = new PHPGraphLib(650,200, "image.png")
Upvotes: 0