天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php生成圖形(Libchart)實(shí)例

統(tǒng)計(jì)圖形就我們會(huì)常到的數(shù)據(jù)圖形了,如果三個(gè)數(shù)組以圖形顯示或樓盤(pán)以圖形走向我們都會(huì)要用到圖形,下面我來(lái)介紹一個(gè)php LIbchart圖形生成類(lèi)吧,很用的有需要的朋友可參考。
簡(jiǎn)單全數(shù)字或英文的就可以直接使用下面類(lèi)了(libchart類(lèi)大家可自行百度下載)
復(fù)制代碼 代碼如下:
<?
 /*
  update by Leo
  It's draw the pic of Sheet,and it will take all the num on the pic.
 */
 require "./libchart/classes/libchart.php";
 class drawPic{
  var $chart;
  var $style;
  function drawPic($style="1",$width="500",$height="250"){
   $this->style=$style;
   if($style==1){
    //cylinder
    $this->chart = new VerticalBarChart($width,$height);
   }else if($style==2){
    //line
    $this->chart = new LineChart($width,$height);
   }else if($style==3){
    //Lump
    $this->chart = new PieChart($width,$height);
   }else{
    //cross
    $this->chart=new HorizontalBarChart($width,$height);
   }
  }

  function draw($obj){

   if($this->style==1||$this->style=="1"){
    //cylinder
    $dataSet = new XYDataSet() ;
    $this->chart->setTitle($obj->title);//title
    $arr=array();
    $arr=$obj->dataArray;
    foreach($arr as $key => $val){
     $dataSet->addPoint ( new Point($key,$val)) ;
    }
    $this->chart->setDataSet ( $dataSet ) ;
    $this->chart->render();
   }else if($this->style==2||$this->style=="2"){
    //line
    $this->chart->setTitle($obj->title);//title
    $arr=array();
    $arr=$obj->dataArray;
    $i=0;
    $dataSet = new XYSeriesDataSet();
    foreach($arr as $key => $val){
     $serie{$i}= new XYDataSet();
     foreach($val as $k => $v){
      $serie{$i}->addPoint(new Point($k,$v));
     }
     $dataSet->addSerie($key,$serie{$i});
     $i=$i+1;
    }
    $this->chart->setDataSet($dataSet);
    $this->chart->render();
   }else if($style==3){
    //Lump
    $dataSet = new XYDataSet() ;
    $this->chart->setTitle($obj->title);//title
    $arr=array();
    $arr=$obj->dataArray;
    foreach($arr as $key => $val){
     $dataSet->addPoint ( new Point($key."($val)",$val)) ;
    }
    $this->chart->setDataSet ( $dataSet ) ;
    $this->chart->render();
   }else{
    //cross
    $dataSet = new XYDataSet();
    $this->chart->setTitle($obj->title);//title
    $arr=array();
    $arr=$obj->dataArray;
    foreach($arr as $key => $val){
     $dataSet->addPoint ( new Point($key,$val)) ;
    }
    $this->chart->setDataSet($dataSet);
    $this->chart->render();
   }
  }

 }
 class kkk{};
 $n=new drawPic("4");//it will set 1 or 2 or 3 or 4
 $k=new kkk();
 $k->dataArray=array("2000"=>"30","2001"=>"40","2002"=>"50","2003"=>"60","2004"=>"70","2005"=>"80","20020"=>"90");//style==1 or style=2 or style=4
 //$k->dataArray=array("2000"=>"30","2001"=>"40","2002"=>"50","2003"=>"60","2004"=>"70","2005"=>"80","20020"=>"90");//style==3
 //$k->dataArray=array("yi"=>array("2000"=>"30","2001"=>"40","2002"=>"50","2004"=>"60"),"er"=>array("2003"=>"60","2004"=>"70","2005"=>"80","20020"=>"90"),"san"=>array("33"=>"12","45"=>"56","89"=>"45","86"=>"49"));//style==2 and the years will show first array to block.(it will be show 2000 2001 2002 2004)
 $k->title="The Sheet title";
 $n->draw($k);
?>
 
紅色字體為調(diào)用。方法1,2,4為相同的數(shù)組。3為線(xiàn)性圖,有可能有兩條線(xiàn)或者多條線(xiàn)的比較(也可以單線(xiàn))。
如果要使用中文可能會(huì)發(fā)現(xiàn)libchart中文亂碼 了,下面找了一個(gè)辦法

我們的應(yīng)用主源代碼如下:
復(fù)制代碼 代碼如下:
<?php
   header("content-type:image/png"); 
   require_once('libchart/classes/libchart.php');

   $chart = new VerticalBarChart( 500 , 250 ) ; // 參數(shù)表示需要?jiǎng)?chuàng)建的圖像的寬和高
   $dataSet = new XYDataSet() ; // 實(shí)例化一個(gè) XY 軸數(shù)據(jù)對(duì)象

     // 為這個(gè)對(duì)象增加四組數(shù)據(jù)集合, Point 對(duì)象的第一個(gè)參數(shù)表示 X 軸坐標(biāo),
// 第二個(gè)表示 Y 軸坐標(biāo)
   $str = '二月';

$str = mb_convert_encoding($str, "html-entities","utf-8" );

$dataSet -> addPoint ( new Point( "Jan 2005" , 273 )) ;
    $dataSet -> addPoint ( new Point( "$str" , 120 )) ;
    $dataSet -> addPoint ( new Point( "March 2005" , 442 )) ;
    $dataSet -> addPoint ( new Point( "April 2005" , 600 )) ;
     // 把這個(gè)數(shù)據(jù)集合傳遞給圖形對(duì)象
    $chart -> setDataSet ( $dataSet ) ;
    // 設(shè)置圖形的標(biāo)題,并把它作為一個(gè) png 文件渲染
    $chart -> setTitle ( "統(tǒng)計(jì)圖" ) ;

    //$chart -> render ( "demo/generated/demo1.png" ) ;
    // 這里需要一個(gè)路徑和文件名稱(chēng)
    //就這么簡(jiǎn)單一個(gè)像下圖一樣美麗的柱狀圖就出來(lái)了
    $chart -> render () ;
?>
 
標(biāo)紅字的地方是為了解決中文亂碼的。
2、標(biāo)題亂碼:
默認(rèn)顯示中文是亂碼,這是由于編碼的原因,做如下修改:
首先,更改libchar/libchart/classes/view/chart/Chart.php,找到如下內(nèi)容:
復(fù)制代碼 代碼如下:
public function setTitle($title) {          
            $this->plot->setTitle($title);
        }

更改為:
復(fù)制代碼 代碼如下:
public function setTitle($title) {
        $title = mb_convert_encoding($title, "html-entities","utf-8" );
           $this->plot->setTitle($title);
}

第三步:就是上面某個(gè)博客里講到的:
1、自己寫(xiě)的使用Libchart 庫(kù)生成圖表的php 文件以u(píng)tf-8編碼保存
       2、找?guī)讉€(gè)中文字體庫(kù),比如華文行楷、宋體等等,復(fù)制到libchart fonts目錄下
        3、修改libchart classes目錄下的text.php 文件
第47、48行

復(fù)制代碼 代碼如下:
$this->fontCondensed = dirname(__FILE__) . "/../fonts/DejaVuSansCondensed.ttf";
$this->fontCondensedBold = dirname(__FILE__) . "/../fonts/DejaVuSansCondensed-Bold.ttf";

改為
復(fù)制代碼 代碼如下:
$this->fontCondensed = dirname(__FILE__) . "/../fonts/你找來(lái)的中文字體";
$this->fontCondensedBold = dirname(__FILE__) . "/../fonts/你找來(lái)的中文字體";
 

我修改的:
復(fù)制代碼 代碼如下:
public function Text() {
    $baseDir = dirname(__FILE__) . "/../../../";

    // Free low-res fonts based on Bitstream Vera <http://dejavu.sourceforge.NET/wiki/>
   $this->fontCondensed = $baseDir . "fonts/FANGZHENGFANGSONG.ttf";
    $this->fontCondensedBold = $baseDir . "fonts/FANGZHENGFANGSONG.ttf";
   }
 
FANGZHENGFANGSONG.ttf 這個(gè)文件是我找的方正仿宋簡(jiǎn)體字庫(kù),我把中文名字改成那個(gè)樣子了,其實(shí)不改也是可以的。

php技術(shù)php生成圖形(Libchart)實(shí)例,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 97精品在线播放 | 亚洲AV永久无码精品老司机蜜桃 | 99热这里只有精品88 | 色综合99久久久国产AV | 69国产精品人妻无码免费 | 蜜臀AV人妻久久无码精品麻豆 | 亚洲高清在线视频 | 亚洲大码熟女在线 | 国产色情短视频在线网站 | 超碰免费视频部落格 | 亚洲精品无码一区二区三区四虎 | 色AV色婷婷96人妻久久久 | 成人国产在线视频 | 日本无卡无吗在线 | 亚洲中文字幕在线第六区 | 女警被黑人20厘米强交 | 亚洲无线观看国产 | 扒开美女下面粉嫩粉嫩冒白浆 | 中文有码中文字幕免费视频 | 久久视频这里只精品6国产 久久视频在线视频观品15 | 成人无码精品1区2区3区免费看 | 2012中文字幕在线动漫电影 | 亚洲欧美一区二区三区久久 | 动漫美女和男人下载 | 美女胸禁止18以下看 | 国产精品久久久久久免费字体 | 忘忧草在线社区WWW日本直播 | yellow在线观看免费直播 | 亚洲中久无码永久在线 | 欧美精品色婷婷五月综合 | 武汉美女洗澡 | 亚洲人成色777777老人头 | 性欧美FREE少妇XXX | 亚洲1卡二卡3卡4卡新区在线 | 美女诱惑性感揉胸 | 99视频精品国产免费观看 | 美女的让男人桶爽网站 | WWW夜片内射视频在观看视频 | 耻辱诊察室1一4集动漫在线观看 | 国产日韩久久久精品影院首页 | 亚洲免费视频日本一区二区 |