我正在使用PHP Jpgraph库从mysql查询生成的数组创建图形。
我已经编写了以下php代码:
require_once('jpgraph/src/jpgraph.php');
require_once('jpgraph/src/jpgraph_bar.php');
foreach ($results as $key => $value){
$data[] = $value['num_rows'];//$data = array(740,902,647,208);
$data1[] = $value['department_name'];//$data1 = array('Epi', 'Dss', 'Bio', 'Clin');
}
$graph = new Graph(450,200,"auto");
$graph->SetScale("textlin");
$graph->img->SetMargin(40,30,40,40);
$graph->SetShadow();
$graph->xaxis->SetTickLabels($data1);
$bplot = new BarPlot($data);
$bplot->SetFillColor("lightgreen");
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD);
$bplot->value->SetAngle(45);
$bplot->value->SetColor("black","navy");
$graph->Add($bplot);
$graph->Stroke();
我希望jpgraph生成一个条形图。但是,我得到一个空白页,并显示一条消息“图像'http://localhost/KVL/showgraph”,因为其中包含错误,所以无法显示。我已经在终端上运行php -m
,可以看到已安装GD扩展。我正在运行php 7.2
。