php報(bào)表之jpgraph柱狀圖實(shí)例代碼
更新時(shí)間:2011年08月22日 23:30:12 作者:
jpgraph是php中一個(gè)非常非常強(qiáng)大的第三方報(bào)表工具,據(jù)說(shuō)能完成一切你想要的圖形
新手初識(shí)jpgraph肯定會(huì)遇到各種各樣的問(wèn)題,比如亂碼什么的,本案例是jpgraph3.0.7制作,也經(jīng)過(guò)本人的多次實(shí)驗(yàn),解決亂碼問(wèn)題
<?php
$datay=array(); //縱坐標(biāo)數(shù)據(jù)
$datax=array(); //橫坐標(biāo)數(shù)據(jù)
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″,”用戶消費(fèi)報(bào)表圖”));
$graph->xaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用戶姓名”));
$graph->yaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用戶訂單數(shù)量”));
$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();
?>
復(fù)制代碼 代碼如下:
<?php
$datay=array(); //縱坐標(biāo)數(shù)據(jù)
$datax=array(); //橫坐標(biāo)數(shù)據(jù)
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″,”用戶消費(fèi)報(bào)表圖”));
$graph->xaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用戶姓名”));
$graph->yaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用戶訂單數(shù)量”));
$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();
?>
效果圖:
官方網(wǎng)站 http://jpgraph.net/download/ 腳本之家下載地址 http://chabaoo.cn/codes/38194.html
相關(guān)文章
mysql desc(DESCRIBE)命令實(shí)例講解
這篇文章主要介紹了mysql desc(DESCRIBE)命令實(shí)例講解的相關(guān)資料,需要的朋友可以參考下2016-09-09PHP面向?qū)ο蟪绦蛟O(shè)計(jì)(OOP)之方法重寫(override)操作示例
這篇文章主要介紹了PHP面向?qū)ο蟪绦蛟O(shè)計(jì)(OOP)之方法重寫(override)操作,簡(jiǎn)單描述了php面向?qū)ο蟪绦蛟O(shè)計(jì)中方法重寫的原理,并結(jié)合實(shí)例形式分析了php方法重寫相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下2018-12-12淺析PHP安裝擴(kuò)展mcrypt以及相關(guān)依賴項(xiàng)(PHP安裝PECL擴(kuò)展的方法)
本篇文章是對(duì)PHP安裝擴(kuò)展mcrypt以及相關(guān)依賴項(xiàng)(PHP安裝PECL擴(kuò)展的方法)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07在WordPress中使用wp_count_posts函數(shù)來(lái)統(tǒng)計(jì)文章數(shù)量
這篇文章主要介紹了在WordPress中使用wp_count_posts函數(shù)來(lái)統(tǒng)計(jì)文章數(shù)量的方法,同時(shí)也可以統(tǒng)計(jì)草稿及頁(yè)面的數(shù)量,相當(dāng)實(shí)用,需要的朋友可以參考下2016-01-01