0

我有一组来自 JpGraph 的代码来帮助我创建条形图。

<?php
require_once ('src/jpgraph.php');
require_once ('src/jpgraph_bar.php');
$datay=array(1992,1993,1995,1996,1997,1998,2001);

// Size of graph
$width=400;
$height=500;

// Set the basic parameters of the graph
$graph = new Graph($width,$height);
$graph->SetScale('textlin');

$top = 60;
$bottom = 30;
$left = 80;
$right = 30;
$graph->Set90AndMargin($left,$right,$top,$bottom);

// Nice shadow
$graph->SetShadow();

// Setup labels
$lbl = array("Andrew\nTait","Thomas\nAnderssen","Kevin\nSpacey","Nick\nDavidsson",
"David\nLindquist","Jason\nTait","Lorin\nPersson");
$graph->xaxis->SetTickLabels($lbl);

// Label align for X-axis
$graph->xaxis->SetLabelAlign('right','center','right');

// Label align for Y-axis
$graph->yaxis->SetLabelAlign('center','bottom');

// Titles
$graph->title->Set('Number of incidents');

// Create a bar pot
$bplot = new BarPlot($datay);
$bplot->SetFillColor('orange');
$bplot->SetWidth(0.5);
$bplot->SetYMin(1990);

?>

但是,这只有在我把它放在我的代码顶部时才有效。如果我把它放在其他任何地方,它将无法显示。有什么办法可以克服这个问题,如果我把代码专门放在一个地方,例如它会出现在那里?此外,我将使用我自己的数据库中的一些数据作为该图的值。

谢谢你。

4

4 回答 4

1

需求/包含在运行时解决,而不是在解析期间解决。这允许它们被动态调用。因此,必须先完成它们,然后才能引用它们的任何代码。

要查看的替代方法是autoloadspl_autoload。这允许在第一次引用时加载类文件。

但是,从您的评论来看,问题似乎是使用 JpGraph 需要发送标头。您需要检查studentcourse.php是否生成了任何输出(包括无意的空格)。

于 2012-01-19T20:05:44.373 回答
1

JpGraph 创建一个显示的图像。您不能同时输出文本和图像。

于 2012-01-19T20:06:52.183 回答
0

好吧,您无法逃避这样一个事实,即当您调用 时new Graph(),该类应该已经存在,因此如果您在该行之后包含文件,它将永远无法工作。

于 2012-01-19T20:04:57.680 回答
0

这会生成图像,对吗?

我会将其单独放入一个文件中,然后在您希望显示图表的页面上,只需执行以下操作:

<img src="myGraph.php">
于 2012-01-19T20:31:25.920 回答