JPGraph将系列值加在一起

时间:2010-08-18 22:10:52

标签: php graphics jpgraph

我确定我在这里做了一些愚蠢的事情,但有人可以解释为什么jpgraph将两个系列值加在一起吗?我特别谈到价值$ a1 [3]和$ a2 [3]以及$ a1 [10]和$ a2 [10]加在一起。您可以see the graphs here并将代码粘贴在下方:

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

1 个答案:

答案 0 :(得分:0)

我认为你错过了图表 - &gt;添加。请尝试以下方法:

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