Printing data on the side after generating a graph using JGraph library in PHP
Question
Hello I need to generate a report which would include both data and a graph image which is a pictorial representation of the data printed. Now the problem is, the function "stroke" in jpgraph generates the graph, so I get an error if I try to echo any information before the stroke function, and nothing prints onto the browser after the stroke function is executed. Do anybody know a way around for this problem??
Is there any other method to generate a report which has both the graph and tabular data.
Solution
JPGraph's Stroke() function will create the graph for you, but you can also pass a filename into the function. This will save the graph as an image which you can then load onto your report, and also output other data around it. For example:
// build graph code....
$graph->Stroke('mygraph.png');
echo "<img src='mygraph.png' alt='my graph' />";
echo "Anything I want to go with the graph";
OTHER TIPS
Thanks for your precious information.
Instead of $graph->stroke('mygraph.png')
you can try :
$img = $graph->stroke(_IMG_HANDLER);
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($img); //**Feed jpgraph image resource**
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
Pl have look on phpexcel tests directory example name 25inmemoryimage.php
If you are using phpExcel, you can import image into excel easy. Like this: http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=28138