JpGraph php 图形库 - 麻烦嵌入图形

JpGraph php graph library - trouble embedding graph

我已经成功地使用 JpGraph 创建了一个图表,现​​在我想更进一步并将该图表嵌入到我的 template/view php 文件中。

所以我将图形代码放入一个单独的 php 文件中然后嵌入,但是,当我尝试通过以下方式嵌入它时 <embed src="templates/ctl008/graphshow.php" height=80em; width=160em;> </embed> 它给我留下了 requested URL not found 错误。

我摆弄了路径并尝试了:graphshow.phpctl008/graphshow.php 和其他类似的变体。是我的路径不正确还是我还缺少其他东西?我还尝试将其嵌入 <img src="graphshow.php" /> .

一个有趣的怪癖是当我打开 ini_set('display_errors', 1); error_reporting(E_ALL); 并尝试自行查看图表时一条错误消息:JpGraph Error: HTTP headers have already been sent. Caused by output from file gd_image.inc.php at line 92. 但如果我关闭 error_reporting 它会按预期显示图形。

我将不胜感激任何指向正确方向的指示:)

这是我的 graphshow.php 文件:

<?php require_once ('../library/include/jpgraph/src/jpgraph.php');
require_once ('../library/include/jpgraph/src/jpgraph_line.php');
require_once ('../library/include/jpgraph/src/jpgraph_bar.php');
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
$gasArray = array();
foreach($searchArray as $gArray){
    $gasArray[] = $gArray['GASVB'];
}
$stromArray = array();
foreach($searchArray as $sArray){
    $stromArray[] = $sArray['STROVB'];
}
$olArray = array(); 
foreach($searchArray as $oArray){
    $olArray[] = $oArray['OLVB'];
}

 if(!empty($gasArray) || !empty($stromArray) || !empty($olArray)){
     ob_end_clean();
 $width= 1200;
 $height = 400;
 $graph = new Graph($width, $height);
 $graph->SetScale('intint');
 
 $graph->title->Set('Energie Verbrauch');
 $graph->SetMargin(80,25,30,80);
 
 $graph->xaxis->title->Set('Datum');
 $graph->yaxis->title->Set('Verbrauch');
 // print_r($dateArray);
 
 $lineGas = new LinePlot($gasArray);
 $lineGas->SetLegend('Gas');
 $lineStrom = new LinePlot($stromArray);
 $lineStrom->SetLegend('Strom');
 $lineOl = new LinePlot($olArray);
 $lineOl->SetLegend('ÖL');
 
 $graph->Add($lineGas);
 $graph->Add($lineStrom);
 $graph->Add($lineOl);
 $graph->Stroke();
 }
?>

我想从一些有用的链接开始:

http://www.digialliance.com/docs/jpgraph/html/2210intro.html
https://coursesweb.net/php-mysql/jpgraph-graph-charts-plots-php
https://jpgraph.net/download/manuals/chunkhtml/ch05s05.html

现在那已经不在了,我是如何让它工作的:

从上面 Whosebug link 中的 advice/help 开始,我将单独的 php 文件变成了 function 我的 graphshow.php 函数的最后一行是这样的:$graph->Stroke("charts/graphEnergy.png"); 其中 charts 是我要保存的文件夹,graphEnergy.png 是要保存的文件的名称。

然后在我的 view/template 页面中,我 require_once('chart/ctl008/graphshow.php'); 使我的 php 文件可访问,像这样调用我的函数 generateGraph($gasArray, $stromArray, $olArray);

然后在 html 部分用 <img src="./charts/graphEnergy.png" />

嵌入了图表 真正让我失望的是 需要调用 graph.png charts/graphEnergy.php 之前的 ./,然后我能够在我的 view/template 页面上显示我的 bootiful 图表。

我希望这对未来:)

  • BoogaBooga