php柱狀圖(JpGraph類庫)的產生方法分享

來源:互聯網
上載者:User
  1. DEFINE("CACHE_DIR","/tmp/jpgraph_cache/");'
  2.   DEFINE("TTF_DIR","/usr/X11R6/lib/X11/fonts/truetype/");
複製代碼

Windows系統改為:  

  1.  DEFINE("CACHE_DIR","c:/apache/htdocs/ jpgraph_cache/");'
  2.   DEFINE("TTF_DIR","c:/windows/fonts");
複製代碼

注意事項:   (1)cache(緩衝)檔案夾路徑可以自己定義,而TTF(字型)檔案夾必須是%system%/Fonts。  (2)確保PHP對cache(緩衝)檔案夾有寫的許可權。 5、   完成上述設定後就可以使用JpGraph了,可以先將JpGraph的例子copy到htdocs檔案夾中,運行一下看看。

從資料庫中讀取資料到jpgraph圖表中 1、 將./src/Examples目錄中的檔案example16.2.php以及./src目錄中的檔案jpgraph_bar.php、jpgraph_gradient.php、jpgraph_line.php、jpgraph_plotmark.inc、jpgraph.php拷貝到同一目錄下。

2、   建立資料庫jpg,資料庫表test   建立2個欄位:   id(主鍵):int   number:int   並添加一些資料 3、   修改example16.2.php   修改後的代碼

  1.   include ("jpgraph.php");
  2.   include ("jpgraph_line.php");
  3.   include ("jpgraph_bar.php");
  4.   $connect=mysql_connect("localhost","root","");
  5.   mysql_select_db("jpg",$connect);
  6.   $query=mysql_query("select * from test",$connect);
  7.   $i=0; // bbs.it-home.org
  8.   while ($array=mysql_fetch_array($query)) {
  9.   $l2datay[$i]=$array["number"];
  10.   $i++;
  11.   }
  12.   mysql_close($connect);
  13.   // Create the graph.
  14.   $graph = new Graph(400,200,"auto");
  15.   $graph->SetScale("textlin");
  16.   $graph->img->SetMargin(40,130,20,40);
  17.   $graph->SetShadow();
  18.   // Create the bar plot
  19.   $bplot = new BarPlot($l2datay);
  20.   $bplot->SetFillColor("orange");
  21.   $bplot->SetLegend("Result");
  22.   // Add the plots to t'he graph
  23.   $graph->Add($bplot);
  24.   $graph->title->Set("Adding a line plot to a bar graph v1");
  25.   $graph->xaxis->title->Set("X-title");
  26.   $graph->yaxis->title->Set("Y-title");
  27.   $graph->title->SetFont(FF_FONT1,FS_BOLD);
  28.   $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
  29.   $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
  30.   //$graph->xaxis->SetTickLabels($datax);
  31.   //$graph->xaxis->SetTextTickInterval(2);
  32.   // Display the graph
  33.   $graph->Stroke();
  34. ?>
複製代碼

說明:JpGraph的最新版本為 Version: 3.5.0b1。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.