php繪製雙柱形圖

<?php
 // content="text/plain; charset=utf-8"
require_once('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');


$datay=array(80,78,50,66,45);
$datay2=array(40,60,70,50,30);
$x = array("Watermelon","apple","pear","banana","Strawberry");  //設置x軸數據


//創建畫布
$graph = new Graph(600,400);
$graph->SetScale("textlin");;
//$graph->yaxis->scale->SetGrace(10);

$graph -> xaxis -> SetTickLabels($x); 
//統計圖標題
$graph->title->set(iconv("gb2312","gb2312", "水果一月、二月份銷售量"));
$graph->title->SetFont(FF_SIMSUN, FS_NORMAL,15);   //標題字體
 $graph -> xaxis -> title -> SetFont(FF_SIMSUN,FS_BOLD);
 $graph -> xaxis -> title -> Set(iconv("gb2312", "gb2312", "水果名稱"));
 $graph -> yaxis -> title -> SetFont(FF_SIMSUN,FS_BOLD);
 $graph -> yaxis -> title -> Set(iconv("gb2312", "gb2312", "數量(公斤)"));


//設置背景格子
$graph->ygrid->Show(true,true);
$graph->ygrid->SetColor('gray','[email protected]');
$graph->SetMarginColor('white');


// Create the "dummy" 0 bplot
$bplotzero = new BarPlot($datay2);
$ybplot1 = new BarPlot($datay);
$ybplot = new GroupBarPlot(array($ybplot1,$bplotzero));


//生成圖例
$graph->Add($ybplot);
//顯示縱座標的值
$ybplot1->value->Show();
$bplotzero->value->show();
// .. and finally stroke the image back to browser
$graph->Stroke();

?>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章