【问题标题】:PHP jpgraph parse x and y axis through a url?PHP jpgraph通过url解析x和y轴?
【发布时间】:2014-03-06 19:37:16
【问题描述】:

我有一个 jpgraph 脚本,它解析一个 URL 来为我构建一个图表,如下所示:

如何同时发送 X 轴数据,因为我需要跳过几个月,而当前方法不允许这样做?

我猜它看起来像这样:

/chart/jpgraph/graphmaker.php?a=(Jan','5)&b=(Feb','3)&c=(Jun','4)

“graphmaker.php”中的jpgraph图形代码为:

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

?>

【问题讨论】:

    标签: php parsing url axis jpgraph


    【解决方案1】:

    jpgraph 允许使用“-”跳过字段。我没有设法解决这个问题,但通过将数据集转发为 -,-,2,4,-,1,-,-,5 并制作这样的 URI 找到了解决方法:

    /jpgraph/graphmaker.php?a=-&b=-&c=2&d=4&e=-&f=1&g=-&h=-&i=5&j=-
    

    此修复有效并达到了预期的效果。

    我在这里使用了@PandemoniumSyndicate 建议In PHP compare two arrays then make a new array based on a specific structure?

    然后添加这个来构建传递给 jpgraph 的 URI:

    $urls = range('a', 'j');
    $newArray = array_combine($urls, $ar3);
    $mine = array();
    foreach ($newArray as $key => $value) { $mine[] = "$key=$value"; }
    $plov = implode('&',$mine);
    

    jpgraph 的 URI 是:

    /jpgraph/graphmaker.php?'.$plov.'
    

    希望这对其他人有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-06
      • 2014-06-08
      • 2013-04-29
      • 2012-12-24
      • 2017-04-03
      • 2022-01-16
      • 1970-01-01
      • 2022-01-09
      相关资源
      最近更新 更多