我正在尝试在codeigniter中创建一个图表并将其转换为pdf。对于pdf转换,我使用的是mpdf。
对于图生成我尝试了几种方法。包括 - phpgraphlib,phpmygraph5.0以及gcharts ..
gchart在javascript中生成图表我猜... 所以我尝试了phpgraphlib和phpmygraph5。但是我现在面临的问题是图形在浏览器中生成。坚持如何将其转换为图像并作为数据数组发送到我的pdf视图..
这是我的pdf代码:
$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');
这是生成图形函数:
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;
}
当我从pdf生成函数调用图形函数时,它会直接在浏览器上生成图形...而不是在我加载pdf视图的下一段代码中。如何将此生成的图形保存为图像并且仅将该图像传递给pdf视图??
答案 0 :(得分:0)
将结果图保存为.png图像文件很容易,您必须看到:
Save phpgraphlib graph as image
根据文档,命令是这样的:
$graph = new PHPGraphLib(650,200, "image.png")