php图形jpgraph操作实例分析


Posted in PHP onFebruary 22, 2017

本文实例讲述了php图形jpgraph操作。分享给大家供大家参考,具体如下:

<?php
include ("src/jpgraph.php");
include("src/jpgraph_bar.php");
include ("src/jpgraph_line.php");
//设置显示的数据数组;
//调用类库
//设置图像的大小
$graph = new Graph(400,200,"auto");
$graph->SetScale("textlin");
//设置图形的边距
$graph->img->SetMargin(40,180,40,40);
//设置图形的背景图片,填充方式有:BGIMG_FILLPLOT, BGIMG_FILLFRAME, BGIMG_COPY
$graph->SetBackgroundImage("abc.jpg",BGIMG_FILLPLOT);
$graph->img->SetAngle(45); //设置图形在图像中的角度
//设置背景图片的对比度,must be between -1 <= x <= 1, (0,0)=original image
$graph->AdjBackgroundImage(0,0);
//设置投影;
//$graph->SetShadow();
//设置标题
$graph->title->Set("test image");
//设置标题字体样式
$graph->title->SetFont(FF_FONT1,FS_BOLD);
//设置标题的边距
$graph->title->SetMargin(3);
//设置图列的位置
$graph->legend->Pos(0.05,0.5,"right","center");
//设置图列的投影,颜色
$graph->legend->SetShadow('darkgray@0.1');
$graph->legend->SetFillColor('lightblue@0.3');
//设置x轴的标记
$graph->xaxis->SetTickLabels($label_x);
//设置X轴的显示值的角度;
$graph->xaxis->SetLabelAngle(30);
//设置x轴标题和字体颜色
$graph->xaxis->title->Set('Year 2006');
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetColor('white');
//设置x轴的字体和颜色
$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetColor('yellow');
//设置y轴的字体和颜色
$graph->yaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->SetColor('yellow');
//设置是否显示格子。默认为显示;
//$graph->ygrid->Show(false);
//设置格子的颜色和粗细。值越小,格子越粗。
$graph->ygrid->SetColor('yellow@0.5');
//设置y轴更优美一些
$graph->yaxis->scale->SetGrace(20);
//设置图列的数据
$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
//设置图列的填充颜色
$bplot1->SetFillColor('orange@0.4');
$bplot2->SetFillColor('brown@0.4');
//设置值的格式
$bplot1->value->SetFormat('%d');
//设置图列标签
$bplot1->SetLegend('Label 1');
$bplot2->SetLegend('Label 2');
//设置图列在图中的阴影
$bplot1->SetShadow('black@0.4');
$bplot2->SetShadow('black@0.4');
//生成图列
$gbarplot = new GroupBarPlot(array($bplot1,$bplot2));
$gbarplot->SetWidth(0.9);
$graph->Add($gbarplot);
//生成图形
$graph->Stroke();
//上面所说的时在生成柱形图,当生成线性图时用下面的方法
$p1 = new LinePlot($datay);
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("red");
$p1->mark->SetWidth(4);
$p1->SetColor("blue");
$p1->SetCenter();
$p1->SetLegend("Triumph Tiger -98");
$graph->Add($p1);
$p2 = new LinePlot($data2y);
$p2->mark->SetType(MARK_STAR);
$p2->mark->SetFillColor("red");
$p2->mark->SetWidth(4);
$p2->SetColor("red");
$p2->SetCenter();
$p2->SetLegend("New tiger -99");
$graph->Add($p2);
// Style can also be specified as SetStyle([1|2|3|4]) or
// SetStyle("solid"|"dotted"|"dashed"|"lobgdashed")
$lineplot->SetStyle("dashed");//设置线的样式
$graph->yaxis->scale->SetGrace(20); //设置y轴更优美一些
?>

2.柱形图和饼状图举例

if($tag == 1)
{
$graph = new Graph(600,400,"auto");
$graph->SetScale("textlin");
$graph->setMarginColor('lightblue');
$graph->SetShadow();
$graph->setMargin(30,100,30,60);
//设置标题;
$graph->title->set("文章分类汇总");
$graph->title->SetMargin(3);
$graph->title->setfont(FF_SIMSUN,FS_BOLD);
$graph->title->setcolor('black@0.5');
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->SetFont(FF_SIMSUN,FS_NORMAL);
$graph->xaxis->SetColor('darkblue','black');
$graph->xaxis->SetTickLabels($name);
$graph->xaxis->SetLabelAngle(30);
$bplot = new BarPlot($article_num);
$bplot->SetFillColor("orange");
$bplot->value->SetFormat('%d');
$bplot->SetShadow('darkgray');
$bplot->value->show();
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD);
$bplot->SetLegend("文章数");
$graph->Add($bplot);
$graph->Stroke();
}
else
{
$graph1 = new PieGraph(600,400,"auto");
$graph1->SetScale("textlin");
$graph1->SetShadow();
$graph1->title->setFont(FF_SIMSUN,FS_BOLD);
$graph1->title->set("用户文章饼形图");
$graph1->setMargin(30,100,30,60);
$p1 = new pieplot3d($article_num);
$p1->setAngle(80);
$p1->setsize(0.5);
$p1->setShadow();
$p1->ExplodeSlice(2);
$p1->SetCenter(0.4);
$graph1->legend->SetFont(FF_SIMSUN,FS_NORMAL);
$graph1->legend->setshadow();
$p1->SetLegends($name);
$graph1->Add($p1);
$graph1->Stroke();
}
//生成本地图片
$graph->Stroke("路径/文件名.png");

希望本文所述对大家PHP程序设计有所帮助。

PHP 相关文章推荐
PHP完整的日历类(CLASS)
Nov 27 PHP
Linux下进行MYSQL编程时插入中文乱码的解决方案
Mar 15 PHP
zend framework多模块多布局配置
Feb 26 PHP
PHP面向对象学习笔记之二 生成对象的设计模式
Oct 06 PHP
php连接函数implode与分割explode的深入解析
Jun 26 PHP
腾讯微博提示missing parameter errorcode 102 错误的解决方法
Dec 22 PHP
php通过rmdir删除目录的简单用法
Mar 18 PHP
php递归实现无限分类的方法
Jul 28 PHP
谈谈你对Zend SAPIs(Zend SAPI Internals)的理解
Nov 10 PHP
Linux平台php命令行程序处理管道数据的方法
Nov 10 PHP
php5.x禁用eval的操作方法
Oct 19 PHP
TP5.0框架实现无限极回复功能的方法分析
May 04 PHP
关于php几种字符串连接的效率比较(详解)
Feb 22 #PHP
php可变长参数处理函数详解
Feb 22 #PHP
php操作access数据库的方法详解
Feb 22 #PHP
Smarty3配置及入门语法
Feb 22 #PHP
PHP中ajax无刷新上传图片与图片下载功能
Feb 21 #PHP
PHP+JavaScript实现无刷新上传图片
Feb 21 #PHP
PHP编辑器PhpStrom运行缓慢问题
Feb 21 #PHP
You might like
php设计模式 Observer(观察者模式)
2011/06/26 PHP
php-cli简介(不会Shell语言一样用Shell)
2013/06/03 PHP
php自动获取关键字的方法
2015/01/06 PHP
php脚本运行时的超时机制详解
2016/02/17 PHP
Ajax提交表单时验证码自动验证 php后端验证码检测
2016/07/20 PHP
PHP实现双链表删除与插入节点的方法示例
2017/11/11 PHP
php中通用的excel导出方法实例
2017/12/30 PHP
jQuery 注意事项 与原因分析
2009/04/24 Javascript
window.name代替cookie的实现代码
2010/11/28 Javascript
Jquery为a标签的href赋值实现代码
2013/05/03 Javascript
window.print打印指定div实例代码
2013/12/13 Javascript
js根据日期判断星座的示例代码
2014/01/23 Javascript
jquery 仿锚点跳转到页面指定位置的实例
2017/02/14 Javascript
学习使用Bootstrap输入框、导航、分页等常用组件
2017/05/11 Javascript
详谈JS中数组的迭代方法和归并方法
2017/08/11 Javascript
PostgreSQL Node.js实现函数计算方法示例
2019/02/12 Javascript
详解easyui 切换主题皮肤
2019/04/04 Javascript
Vue替代marquee标签超出宽度文字横向滚动效果
2019/12/09 Javascript
如何实现vue的tree组件
2020/12/03 Vue.js
Python中shutil模块的学习笔记教程
2017/04/04 Python
基于python操作ES实例详解
2019/11/16 Python
Python Gluon参数和模块命名操作教程
2019/12/18 Python
解决Python数据可视化中文部分显示方块问题
2020/05/16 Python
Python用K-means聚类算法进行客户分群的实现
2020/08/23 Python
python 30行代码实现蚂蚁森林自动偷能量
2021/02/08 Python
通过canvas转换颜色为RGBA格式及性能问题的解决
2019/11/22 HTML / CSS
泰海淘:泰国king Power王权免税集团旗下跨境海淘综合型电商
2020/07/26 全球购物
中层干部竞争上岗演讲稿
2014/01/13 职场文书
21岁生日感言
2014/02/27 职场文书
个人工作主要事迹
2014/05/08 职场文书
公司自我介绍演讲稿
2014/08/21 职场文书
社区党的群众路线教育实践活动剖析材料
2014/10/09 职场文书
公司员工辞职信范文
2015/05/12 职场文书
英语版自我评价,35句话轻松搞定
2019/10/08 职场文书
MyBatis-Plus 批量插入数据的操作方法
2021/09/25 Java/Android
浅析python中特殊文件和特殊函数
2022/02/24 Python