如何在php中为组栏Jpgraph列图设置标签图像

时间:2012-12-23 10:17:44

标签: php jpeg jpgraph

这是我的jpgraph演示代码:

<?php
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

$datay1=array(35,160,0,0,0,0);
$datay2=array(35,190,190,190,190,190);
$datay3=array(20,70,70,140,230,260);

$graph = new Graph(450,200,'auto');    
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40,30,40,40);
$graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());

$graph->xaxis->title->Set('Year 2002');
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$graph->title->Set('Group bar plot');
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
$bplot3 = new BarPlot($datay3);

$bplot1->SetFillColor("orange");
$bplot2->SetFillColor("brown");
$bplot3->SetFillColor("darkgreen");

$gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3));
$gbarplot->SetWidth(0.6);
$graph->Add($gbarplot);

$graph->Stroke();
?>

此代码没有错误,这是完美的...我的问题是如何设置此组标签的图像标签以识别这些颜色条......

norml out put chart是这样的:enter image description here

需要设置此标签图片: enter image description here

我想要这样的最终结果: enter image description here

我该怎么办?

1 个答案:

答案 0 :(得分:1)

这是我的代码:

<?php
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

$datay1=array(35,160,0,0,0,0);
$datay2=array(35,190,190,190,190,190);
$datay3=array(20,70,70,140,230,260);

$graph = new Graph(450,200,'auto');    
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40,30,40,40);
$graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());

$graph->xaxis->title->Set('Year 2002');
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$graph->title->Set('Group bar plot');
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
$bplot3 = new BarPlot($datay3);

$bplot1->SetFillColor("orange");
$bplot2->SetFillColor("brown");
$bplot3->SetFillColor("darkgreen");

$gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3));
$gbarplot->SetWidth(0.6);


$graph->legend->SetPos(0.12,0.01,'left','top');
$graph->legend->SetLayout(LEGEND_VERT);
$graph->legend->SetFrameWeight(1);

$bplot1->SetLegend("Pass");
$bplot2->SetLegend("Fail");
$bplot3->SetLegend("Not Eligible");


$graph->Add($gbarplot);

$graph->Stroke();
?>

生成的图表是:Test bar chart with legend

我希望这能帮助您实现目标。