1. 能做柱状, 饼图,
<?PHP
include ("lib/jpgraph/jpgraph.php");
include ("lib/jpgraph/jpgraph_bar.php");
include ("lib/jpgraph/jpgraph_pie.php");
include ("lib/jpgraph/jpgraph_pie3d.php");
class createJpgraph{
private $hisColor=null;
private $hisLenLable=null;
private $hisTitle=null;
function createJpgraph(){
}
function setHisColor($hisColor){
$this->hisColor=$hisColor;
}
function setHisLenLable($hisLenLable){
$this->hisLenLable=$hisLenLable;
}
function setHisTitle($title){
$this->hisTitle=$title;
}
function createHistogramGroup($width,$heigth,$dataArr,$Xlable,$name){
// Create the basic graph
$graph = new Graph($width,$heigth,'auto');
$graph->SetScale("textlin");
$graph->img->SetMargin(40,80,30,40);
// Adjust the position of the legend box
$graph->legend->Pos(0.02,0.15);
// Adjust the color for theshadow of the legend
$graph->legend->SetShadow('
[email protected]');
$graph->legend->SetFillColor('
[email protected]');
$graph->legend->SetFont(FF_GOTHIC);
// Get localised version of the month names
$graph->xaxis->SetTickLabels($Xlable);
// Set axis titles and fonts
//$graph->xaxis->title->Set('Year 2002'); // ************title
//$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
//$graph->xaxis->title->SetColor('white');
$graph->xaxis->SetFont(FF_GOTHIC);
$graph->xaxis->SetColor('black');
$graph->yaxis->SetFont(FF_GOTHIC);
$graph->yaxis->SetColor('black');
//$graph->ygrid->Show(false);
$graph->ygrid->SetColor('
[email protected]');
// Setup graph title
$graph->title->Set(mb_convert_kana($this->hisTitle,"K")); //**************title
// Some extra margin (from the top)
$graph->title->SetMargin(3);
$graph->title->SetFont(FF_GOTHIC);
// Create the three var series we will combine
$tempdata=null;
$mergeData=null;
$i=0;
foreach ($dataArr as $key=>$item){
$tempdata[$i]=new BarPlot($item);
$tempdata[$i]->SetFillColor($this->hisColor[$key]);
$tempdata[$i]->SetLegend($this->hisLenLable[$key]);
$tempdata[$i]->SetShadow('
[email protected]');
$mergeData[]=$tempdata[$i];
$i++;
}
$gbarplot = new GroupBarPlot($mergeData);
$gbarplot->SetWidth("0.".count($dataArr));
$graph->Add($gbarplot);
$r=date("ymdHis");
$graph_name = "img_".$name.$r.".png";
$graph->Stroke($graph_name);
return $graph_name;
}
function createHistogram($width,$heigth,$data,$Xlable,$name){
// Create the basic graph
$graph = new Graph($width,$heigth,'auto');
$graph->SetScale("textlin");
$graph->img->SetMargin(40,80,30,40);
// Adjust the position of the legend box
$graph->legend->Pos(0.02,0.15);
// Adjust the color for theshadow of the legend
$graph->legend->SetShadow('
[email protected]');
$graph->legend->SetFillColor('
[email protected]');
$graph->legend->SetFont(FF_PGOTHIC); //FF_PGOTHIC
// Get localised version of the month names
$graph->xaxis->SetTickLabels($Xlable);
// Set axis titles and fonts
//$graph->xaxis->title->Set('Year 2002'); // ************title
//$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
//$graph->xaxis->title->SetColor('white');
$graph->xaxis->SetFont(FF_PGOTHIC);
$graph->xaxis->SetColor('black');
$graph->yaxis->SetFont(FF_PGOTHIC);
$graph->yaxis->SetColor('black');
//$graph->ygrid->Show(false);
$graph->ygrid->SetColor('
[email protected]');
// Setup graph title
$graph->title->Set(mb_convert_kana($this->hisTitle,"K")); //**************title
// Some extra margin (from the top)
$graph->title->SetMargin(3);
$graph->title->SetFont(FF_PGOTHIC);
// Create the three var series we will combine
$gbarplot = new BarPlot($data);
$gbarplot->SetFillColor($this->hisColor[0]);
$gbarplot->SetLegend($this->hisLenLable[0]);
$gbarplot->SetShadow('
[email protected]');
//$gbarplot->SetFillGradient("navy","#EEEEEE",GRAD_LEFT_REFLECTION);
$gbarplot->SetWidth(0.3);
$graph->Add($gbarplot);
$r=date("ymdHis");
$graph_name = "img_".$name.$r.".png";
$graph->Stroke($graph_name);
return $graph_name;
}
function createPie($title,$data,$Xlable,$name){
// Create the Pie Graph.
$graph = new PieGraph(350,200,"auto");
if (array_sum($data)!=0){
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set(mb_convert_kana($title,"K"));
$graph->title->SetFont(FF_PGOTHIC);
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.1,0.2);
$graph->legend->SetFont(FF_PGOTHIC);
// Create 3D pie plot
$p1 = new PiePlot3d($data);
$p1->SetTheme("sand");
$p1->SetCenter(0.4);
$p1->SetSize(80);
// Adjust projection angle
$p1->SetAngle(45);
// As a shortcut you can easily explode one numbered slice with
$p1->ExplodeSlice(3);
// Setup the slice values
$p1->value->SetFont(FF_PGOTHIC);
$p1->value->SetColor("navy");
$p1->SetLegends($Xlable);
$graph->Add($p1);
}
$r=date("ymdHis");
$pie_img="img_".$name.$r.".png";
$graph->Stroke($pie_img);
return $pie_img;
}
}
?>