当我在Firefox 35中运行php文件时,它返回图像无法显示,因为它包含错误。
apache v2.4.7php v5.5.9 GD include
<?php
require_once("/jpgraph-3.5.0b1/src/jpgraph.php");
require_once("/jpgraph-3.5.0b1/src/jpgraph_line.php");
require_once("/jpgraph-3.5.0b1/src/jpgraph_date.php");
require_once("/jpgraph-3.5.0b1/src/jpgraph_bar.php");
DEFINE('NDATAPOINTS',1440);
DEFINE('SAMPLERATE',1440);
$graph = new Graph(650,200);
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->AddText($txt2);
$graph ->title->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->SetMargin(60,50,10,35);
$graph->SetScale('datlin');
$graph->title->Set("$date");
$graph->xaxis->SetLabelAngle(0);
$graph->SetImgFormat('jpeg',100);
$graph->SetBackgroundImage("cpu.jpg",BGIMG_FILLFRAME);
$graph->SetTickDensity(TICKD_NORMAL,TICKD_SPARSE);
$graph->xaxis->scale->SetDateFormat('h:i');
$graph->xaxis->scale->SetTimeAlign(MINADJ_1);
$line = new LinePlot($data,$xdata);
$line->SetLegend('CPU');
$graph->yaxis->HideZeroLabel();
$graph->xgrid->Show(true,false);
$graph->xgrid->SetColor('black@0.8');
$line->SetFillColor('chartreuse2@0.6');
$line->SetFillColor('lime@0.4');
$graph->Add($line);
?>
您的代码中有几个错误。首先你应该添加
$graph->Stroke();
在代码末尾输出图像。除了变量$txt2之外,$date和$line都是未定义的。JpGraph将输出带有错误信息的图像,可以帮助您解决所有错误。
将您的代码简化为如下所示的简单代码,RTM,然后一步一步地执行您想要的但在这里没有解释的内容。
$graph = new Graph(650,200);
$date = date("Y-m-d");
$graph->title->Set("$date");
$graph->title->SetFont(FF_ARIAL,FS_BOLD,8);
$graph->SetMargin(60,50,10,35);
$graph->SetScale('dateint');
$graph->xaxis->SetLabelAngle(0);
#$graph->SetBackgroundImage("cpu.jpg",BGIMG_FILLFRAME);
$graph->SetTickDensity(TICKD_NORMAL,TICKD_SPARSE);
$graph->xaxis->scale->SetDateFormat('h:i');
$graph->xaxis->scale->SetTimeAlign(MINADJ_1);
$graph->yaxis->HideZeroLabel();
$graph->xgrid->Show(true,false);
$graph->xgrid->SetColor('black@0.8');
$line = array();
$line[0] = new LinePlot(array(1,2,3),array(time(),time()+300,time()+600));
$line[0]->mark->SetType(MARK_SQUARE);
$graph->Add($line);
$graph->Stroke();