PHP JpGraph:无法显示图像,因为它包含错误

PHP JpGraph:无法显示图像,因为它包含错误,php,Php,当我在Firefox35的php文件中运行该文件时,它返回图像无法显示,因为它包含错误 apache v2.4.7 PHPV5.5.9GD包括 <?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/

当我在Firefox35的php文件中运行该文件时,它返回图像无法显示,因为它包含错误

apache v2.4.7 PHPV5.5.9GD包括

<?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();

谢谢在我添加了$graph->Stroke()之后,这就是给出的结果:致命错误:调用$graph->xaxis->scale->SetDateFormat('h:I')行上未定义的方法LinearScale::SetDateFormat()