我正在尝试从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文件whit命令:
$myPicture->Render($fileName);
然后在主页上
<img src="<?php echo $filename" />
答案 0 :(得分:1)
你必须删除图形文件中php第一行之前的任何空格,因为任何空白行都被认为是echo“”;并且图形文件应该没有echo或print..etc ..然后使用其他文件中的img标签来显示图形..对于我,我将文件命名为graph.php,我将其命名为stat.php并且在lats中我写道..你可以在同一个图形文件中从mysql DB导入数据但是从不在那里打印它们。只使用DB中的数组作为图表的收入数据。我使用英语,因为我的法语不太好
答案 1 :(得分:0)
在要更改为的路径末尾添加斜杠:
chdir("/path/lib/jpgraph-4.0.1/");