2010-08-18 53 views
0

我確定我在這裏做了一些愚蠢的事,但有人可以解釋爲什麼jpgraph將兩個系列值加在一起?我特別提到$ a1 [3]和$ a2 [3]以及$ a1 [10]和$ a2 [10]的值加在一起。您可以see the graphs here和下面的代碼粘貼:JPGraph將系列值加在一起

<?php 
require_once ('src/jpgraph.php'); 
require_once ('src/jpgraph_date.php'); 
require_once ('src/jpgraph_line.php'); 

$x = array(
'8/4/2010', 
'8/5/2010', 
'8/6/2010', 
'8/10/2010', 
'8/11/2010', 
'8/12/2010', 
'8/13/2010', 
'8/14/2010', 
'8/15/2010', 
'8/16/2010', 
'8/17/2010'); 


$a1 = array(
'474', 
'18113', 
'14420', 
'16651', 
'11129', 
'12112', 
'14441', 
'0', 
'0', 
'10206', 
'11702'); 

$a2 = array(
'0', 
'0', 
'0', 
'8003', 
'0', 
'504', 
'0', 
'9204', 
'783', 
'0', 
'7892' 
); 

// Create the graph. 
$graph = new Graph(600, 400); 
$graph->title->Set('A2'); 
$graph->SetScale('intlin'); 
$graph->SetMargin(60,30,60,120); 
$graph->xaxis->SetTickSide(SIDE_BOTTOM); 
$graph->yaxis->SetTickSide(SIDE_LEFT); 

$p0 =new LinePlot($a1); 
$p0->value->Show(); 
$p0->SetLegend('A1'); 
$p0->setWeight(3); 
$p0->SetColor('red'); 

$p1 =new LinePlot($a2); 
$p1->value->Show(); 
$p1->SetLegend('A2'); 
$p1->setWeight(3); 
$p1->SetColor('blue'); 


$ap = new AccLinePlot(array($p1, $p0)); 

$graph->xaxis->SetTickLabels($x); 
$graph->xaxis->SetTextLabelInterval(4); 
$graph->Add($ap); 
$graph->xaxis->SetLabelAngle(90); 
$graph->Stroke(); 

回答

0

我認爲你缺少的graph->添加。請嘗試以下操作:

$p0 = new LinePlot($a1); 
$p0->value->Show(); 
$p0->SetLegend('A1'); 
$p0->setWeight(3); 
$p0->SetColor('red'); 
$graph->Add($p0); 

$p1 = new LinePlot($a2); 
$p1->value->Show(); 
$p1->SetLegend('A2'); 
$p1->setWeight(3); 
$p1->SetColor('blue'); 
$graph->AddY(0,$p1); 
$graph->ynaxis[0]->SetColor('blue'); 

$graph->Stroke();