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

yipeiwu_com5年前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实现无限极分类生成分类树的方法

本文实例讲述了PHP实现无限极分类生成分类树的方法。分享给大家供大家参考,具体如下: 现在的分类数据库设计基本都是:每一个分类有一个id主键字段,一个pid指向父类的id,这样便可实现无...

PHP计算2点经纬度之间的距离代码

复制代码 代码如下:function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitud...

PHP框架Swoole定时器Timer特性分析

PHP框架Swoole定时器Timer特性分析

本文所述PHP框架Swoole定时器Timer特性分析具有很好的实用价值,值得PHP程序开发人员学习借鉴。具体分析如下: 首先,在各种业务型系统中,往往需要服务器在后台扫描相关数据,触发...

20个PHP常用类库小结

图表库 下面的类库可以让你很简的创建复杂的图表和图片。当然,它们需要GD库的支持。 pChart - 一个可以创建统计图的库。 Libchart - 这也是一个简...

PHP安装memcached扩展笔记

PHP安装memcached扩展笔记

最近在服务器上部缓存系统,记录一下PHP安装memcached扩展。 复制代码 代码如下: # 安装服务端 yum install memcached -y I. launchpad...