html - JpGraph 错误 : HTTP headers have already been sent

标签 html jpgraph

问题是 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".

最佳答案

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");
}
?> 

索引.php:

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

希望这对你有用。

关于html - JpGraph 错误 : HTTP headers have already been sent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10487796/

相关文章:

php - 如何在网页中嵌入图表 (jpgraph)

php - 图例颜色错误

jquery - 在不提交的情况下在表单中包含按钮

javascript - 更改具有 ID 的 DIV 内图像的 URL

html - 制作响应标题背景div

html - 调整浏览器大小时图层的位置

php - JpGraph字体文件错误

php - Jpgraph 不会改变我的条形图上的颜色

html - 如何设置与其他边框对齐的边框

php - 替代 jpGraph