gooutya1 发表于 2012-06-12 10:38

php 饼状图问题


大家好,我想在一个php网页上加入一些数据统计图,目前使用的是jpgraph图库,我想在已有的php脚本中加入这些图库,应该如何做?

使用require调用么?我用require要报错。

gooutya1 发表于 2012-06-12 10:45

<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');
// Some data
$data = array(80,20);
// Create the Pie Graph.
$graph = new PieGraph(500,300);

$theme_class="DefaultTheme";
//$graph->SetTheme(new $theme_class());

// Set A title for the plot
$graph->title->Set("HDS AMS2500");
$graph->SetBox(true);

// Create
$p1 = new PiePlot($data);
$graph->Add($p1);

$p1->ShowBorder();
$p1->SetColor('black');
$p1->SetSliceColors(array('red','gray'));
$graph->Stroke();

?>
这是我的一个pie图。我想把它调用入另外的一个网页,作为数据显示,请问如何做?

gooutya1 发表于 2012-06-12 11:03

是我没有表达清楚,还是?请大神指导

amonest 发表于 2012-06-12 11:53

不明白你的问题出在哪里?是require引入有问题?

你最好将错误信息都贴出来。

hbeimf 发表于 2012-06-12 12:58

用include试试

gooutya1 发表于 2012-06-12 13:40

用include也不行呢?你有没有类似的例子

gooutya1 发表于 2012-06-12 13:44

JpGraph Error: HTTP headers have already been sent.
Caused by output from file header.html at line 175.
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".

gooutya1 发表于 2012-06-12 13:49

本帖最后由 gooutya1 于 2012-06-12 13:52 编辑

<!--HTML>
   <HEAD>
      <TITLE>SAN </TITLE>
      <LINK rel="stylesheet" href="./my.css" type="text/css" />
      <LINK rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
   </HEAD>
   <BODY>
-->
<!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"-->
<?php
   include('../config.inc.php');
   require("../header.html");
   print("&nbsp;");
   print("<P><H2><u><i>SAN Operatitions Page of $SAN_NAME</i></u></H2></P>");
include('./pie.php');
?>
.......
下面还有一些form句,和一些表格。我就是想在这个位置插入我的pie图


或者有没有什么群,或者谁愿意给出及时通讯工具,那就最好了,谢谢大家!

xinglu1983 发表于 2012-06-13 09:55

php文件里有header函数,但是你的文件前面又有html输出,当然会报错,跟require没关系。

解决办法:把php文件里涉及header的部分,放到最前面,生成饼图地址后,在你想要的位置输出。

gooutya1 发表于 2012-06-19 10:42

问题已解决,用jpgraph生成的图形,先保存到一个文件中,然后主php文件调用图片就行了
页: [1] 2
查看完整版本: php 饼状图问题