【发布时间】:2017-01-03 23:21:27
【问题描述】:
我正在尝试从this 站点加载条形图示例:
这是我的代码:
error_reporting(E_ALL); ini_set('display_errors', '1');
chdir("/path/lib/jpgraph-4.0.1");
include ("jpgraph.php");
include ("jpgraph_bar.php");
$data1y=array(47,80,40,116);
$data2y=array(61,30,82,105);
$data3y=array(115,50,70,93);
// Create the graph. These two calls are always required
$graph = new Graph(350,200,'auto');
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135));
$graph->SetBox(false);
$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array('A','B','C','D'));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
// Create the bar plots
$b1plot = new BarPlot($data1y);
$b2plot = new BarPlot($data2y);
$b3plot = new BarPlot($data3y);
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));
// ...and add it to the graPH
$graph->Add($gbplot);
$b1plot->SetColor("white");
$b1plot->SetFillColor("#cc1111");
$b2plot->SetColor("white");
$b2plot->SetFillColor("#11cccc");
$b3plot->SetColor("white");
$b3plot->SetFillColor("#1111cc");
$graph->title->Set("Bar Plots");
// Display the graph
$graph->Stroke();
如果我评论“$graph->Stroke();”行,则显示页面(没有图表),但是使用此行,页面全白,没有错误,没有其他字符串显示
在 php 错误日志或 apache 日志上我没有错误
编辑:问题已解决。
我将图表代码放在其他页面(例如chart.php),而不是放在主页面:
<img src="chart.php" />
其他解决方案是使用命令创建一个 png 文件:
$myPicture->Render($fileName);
然后在主页上
<img src="<?php echo $filename" />
【问题讨论】: