问题是我的网页上没有正确显示JpGraph。奇怪的是,如果我单独运行上面的代码,那么它的工作原理。但是如果我将它插入我的主代码中,则无法生成上面显示的消息。 附:我正在使用'ob_start();',但它无法解决问题。
// A new graph with automatic size
$graph = new GanttGraph (0,0, "auto");
// A new activity on row '0'
$activity = new GanttBar (0,"Project", "2001-12-21", "2002-02-20");
$graph->Add( $activity);
// Display the Gantt chart
$graph->Stroke();
?>
</div>
JpGraph Error: HTTP headers have already been sent.
Caused by output from file index.php at line 85.
Explanation:
HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).
Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.
For example it is a common mistake to leave a blank line before the opening "<?php".
答案 0 :(得分:6)
JpGraphs不能存在于带有html的文件中。他们必须在一个纯PHP文件中。为了解决这个问题,我创建了一个生成图形的单独文件,并使整个过程成为一个函数。最后,改变
$graph->Stroke();
到
$graph->Stroke(".<filepaht>.jpg");
然后,在index.php页面中,引用图像文件。
所以,你需要的是,
createjpgraph.php:
<?php
function GenGraph (<input variables>) {
// A new graph with automatic size
$graph = new GanttGraph (0,0, "auto");
// A new activity on row '0'
$activity = new GanttBar (0,"Project", "2001-12-21", "2002-02-20");
$graph->Add( $activity);
// Display the Gantt chart
$graph->Stroke("./foler/file.jpg");
}
?>
的index.php:
...
<div>
...
<?php
include 'createjpgraph.php';
GenerateGraph(<variables>);
?>
<img src=\"./folder/file.jpg\" />
</div>
希望这适合你。
答案 1 :(得分:1)
您甚至可以在同一个html文档中执行此操作 - 首先将图形写入文件,然后显示它......
//Code generating your graph here ...
// Finally output the image to a file
$graph->Stroke("/var/www/html/tmp/out.jpg");
//end of php code
?>
<!-- now include the newly generated image in the HTML -->
<img src="/tmp/out.jpg">
</body>
</html>
&#13;
答案 2 :(得分:0)
似乎在我的情况下,函数创建的jpeg文件无法覆盖...
要覆盖它..
我更改了我的JPGraph文件gd_image.inc.php
..你必须注释掉这一行
说JpGraphError::RaiseL(25111,$aStrokeFileName)