2

问题是 JpGraph 没有正确显示在我的网页上。奇怪的是,如果我单独运行上面的代码,那么它就可以工作。但是如果我将它插入到我的主代码中,它将无法生成上面显示的消息。PS我正在使用'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".
4

3 回答 3

6

JpGraphs 不能存在于带有 html 的文件中。它们必须在一个纯 php 文件中。为了解决这个问题,我创建了一个单独的文件来生成图表,并将整个事情变成一个函数。最后,改变

$graph->Stroke();

$graph->Stroke(".<filepaht>.jpg");

然后,在您的 index.php 页面中,引用图像文件。

所以,看起来你需要的是,

创建jpgraph.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");
}
?> 

索引.php:

...
<div>
...
<?php
include 'createjpgraph.php';
GenerateGraph(<variables>);
?>
<img src=\"./folder/file.jpg\" />
</div>

希望这对你有用。

于 2012-05-10T20:09:43.300 回答
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>

于 2015-01-23T07:06:50.490 回答
0

在我的情况下,似乎无法覆盖该函数正在创建的 jpeg 文件......

覆盖它..我更改了我的 JPGraph 文件gd_image.inc.php..你必须注释掉上面写着的行JpGraphError::RaiseL(25111,$aStrokeFileName)

于 2015-02-21T09:18:07.817 回答