JPGraph 将系列值相加

发布于 2024-09-14 22:54:43 字数 1399 浏览 1 评论 0原文

我确信我在这里做了一些愚蠢的事情,但是有人可以解释为什么 jpgraph 将两个系列值添加在一起吗?我特别讨论的是值 $a1[3] 和 $a2[3] 以及 $a1[10] 和 $a2[10] 加在一起。您可以查看此处的图表,代码粘贴在下面:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉宸 2024-09-21 22:54:43

我认为您缺少图表->添加。请尝试以下操作:

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文