views:

24

answers:

1

I'm sure I'm doing something stupid here but can someone explain why jpgraph is adding two series values together? I'm specifically talking about the values $a1[3] and $a2[3] as well as $a1[10] and $a2[10] being added together. You can see the graphs here and the code is pasted below:

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

I think you are missing the graph->Add. Try the following:

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