jpgraph的一个做图表类


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('darkgray@0.5');
        $graph->legend->SetFillColor('lightblue@0.3');
        $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('white@0.5');
       
        // 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('black@0.4');
            $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('darkgray@0.5');
        $graph->legend->SetFillColor('lightblue@0.3');
        $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('white@0.5');
       
        // 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('black@0.4');
        //$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;
    }
}

?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值