php报表之jpgraph柱状图实例代码

yipeiwu_com6年前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();
?>

效果图:

官方网站 http://jpgraph.net/download/  【宜配屋www.yipeiwu.com】下载地址 https://www.jb51.net/codes/38194.html

相关文章

PHP 5.3和PHP 5.4出现FastCGI Error解决方法

不少童鞋在配置完PHP 5.3或者PHP 5.4网站源码后打开出错,提示 复制代码 代码如下: FastCGI Error The FastCGI Handler was unable...

php取整函数ceil,floo,round的用法及介绍

ceil  是向上进位得到一个值的函数;floor 是舍掉小数位得到一个值的函数;round 是用来四舍五入的函数 ceil定义和用法:ceil() 函数向上舍入为最接近的整数...

老生常谈PHP位运算的用途

在实际应用中可以做用户权限的应用 我这里说到的权限管理办法是一个普遍采用的方法,主要是使用到”位运行符”操作,& 位与运算符、| 位或运行符。参与运算的如果是10进制数,则会被转换至2进...

基于php split()函数的用法详解

PHP函数split()的基本语法为:array split ( string $pattern, string $string [, int $limit] )。我们向大家举了两个例子...

php如何实现只替换一次或N次

 我们都知道,在PHP里Strtr,strreplace等函数都可以用来替换,不过他们每次替换的时候都是全部替换,举个例子: "abcabbc",这个字符串如果使用上边的函数来...