问题描述
我有一个jpgraph脚本,它可以解析URL来为我构建一个图形,如下所示:
I have a jpgraph script that parses a URL to build a graph for me like this:
由于我需要跳过几个月并且当前方法不允许这样做,我如何同时发送X轴数据?
How do I send the X-Axis data at the same time, as I need to skip months and the current method does not allow for this?
我猜它看起来像这样:
/chart/jpgraph/graphmaker.php?a=(Jan','5)&b=(Feb','3)&c=(Jun','4)
"graphmaker.php"中的jpgraph图形代码为:
The jpgraph graph code in "graphmaker.php" is:
<?php
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$parsedurl = parse_url($url, PHP_URL_QUERY);
parse_str($parsedurl);
require_once 'src/jpgraph.php';
require_once 'src/jpgraph_line.php';
$datay1 = array($aa,$bb,$cc,$dd,$ee,$ff,$gg,$hh,$ii,$jj,$kk);
$datay2 = array($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k);
// Setup the graph
$graph = new Graph(600,200);
$graph->SetScale("textlin",1,5);
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('Sept','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May','Jun','Jul'));
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#B22222");
$p1->SetLegend('Attitude');
// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#6495ED");
$p2->SetLegend('Progress');
$graph->legend->SetFrameWeight(1);
// Output line
$graph->Stroke();
?>
推荐答案
jpgraph允许使用-"跳过字段.我没有设法解决这个问题,但是找到了一种解决方法,将数据集转发为-,-,2,4,-,1,-,-,5并制作一个URI,如下所示:
jpgraph allows skipping fields using "-". I didnt manage to solve this issue, but found a workaround by forwarding the dataset as -,-,2,4,-,1,-,-,5 and making a URI like this:
/jpgraph/graphmaker.php?a=-&b=-&c=2&d=4&e=-&f=1&g=-&h=-&i=5&j=-
此修补程序有效并取得了预期的结果.
this fix worked and achieve the desired results.
我在这里使用@PandemoniumSyndicate建议
I used @PandemoniumSyndicate advice here In PHP compare two arrays then make a new array based on a specific structure?
然后添加了此内容以构建URI以传递给jpgraph:
Then added this to build the URI to pass to jpgraph:
$urls = range('a', 'j');
$newArray = array_combine($urls, $ar3);
$mine = array();
foreach ($newArray as $key => $value) { $mine[] = "$key=$value"; }
$plov = implode('&',$mine);
jpgraph的URI是:
The URI to jpgraph was:
/jpgraph/graphmaker.php?'.$plov.'
希望这对其他人有帮助
这篇关于PHP jpgraph通过URL解析x和y轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!