程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php報表 jpgraph柱狀圖實例

php報表 jpgraph柱狀圖實例

編輯:關於PHP編程

jpgraph是php教程中一個非常非常強大的第三方報表工具,據說能完成一切你想要的圖形… 新手初識jpgraph肯定會遇到各種各樣的問題,比如亂碼什麼的,本案例是jpgraph3.0.7制作,也經過本人的多次實驗,解決亂碼問題

<?php

$datay=array(); //縱坐標數據

$datax=array(); //橫坐標數據

foreach ($usernums as $key => $value){
$datay[] = $value;
$datax[] = $userids[$key];
}

require_once (‘jpgraph-3.0.7/jpgraph/jpgraph.php’);
require_once (‘jpgraph-3.0.7/jpgraph/jpgraph_bar.php’);

// Create the graph. These two calls are always required
$graph = new Graph(800,600); //圖像高寬
$graph->SetScale(“textlin”);

$graph->xaxis->SetTickLabels($datax);

$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->xaxis->SetLabelAngle(30);

$graph->yaxis->scale->SetGrace(20);
$graph->xaxis->scale->SetGrace(20);
// Add a drop shadow
$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);

// Create a bar pot
$bplot = new BarPlot($datay);

// Adjust fill color
$bplot->SetFillColor(‘orange’);
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
$bplot->value->SetAngle(45);
$bplot->value->SetFormat(‘%d’);
$graph->Add($bplot);

// Setup the titles
$graph->title->Set(iconv(“UTF-8″, “gb2312″,”用戶消費報表圖”));
$graph->xaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用戶姓名”));
$graph->yaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用戶訂單數量”));

$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);

// Display the graph
$graph->Stroke();

?>
  
效果圖:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved