PHP 绘图——使用jpgraph绘图
来源:互联网 发布:淘宝宝贝图片拍摄技巧 编辑:程序博客网 时间:2024/05/17 22:59
1.要支持中文需要用到simhei.ttf和simsun.ttc这两个字体,在使用中文的时候需要使用SetFont(FF_SIMSUN,FS_BOLD)设置字体。
将需要的字体放入到项目目录下的src\fonts\目录里
在jpgraph.php中有以下这样一段代码是设置字体文件路径的
//
// Setup path for western/latin TTF fonts
//
if (!defined('TTF_DIR')) {
if (strstr( PHP_OS, 'WIN') ) {
$sroot = getenv('SystemRoot');
if( empty($sroot) ) {
$t = new ErrMsgText();
$msg = $t->Get(12,$file,$lineno);
die($msg);
}
else {
define('TTF_DIR', $sroot.'/fonts/');
}
} else {
define('TTF_DIR','/usr/share/fonts/truetype/');
}
}
2.需要注意的是:要想适用jpgraph,你的PHP必须开启了GD2扩展。
如果是在window下首先需要修改文件的路径
修改jpgraph_ttf.inc.php文件
$jpgraph_font_dir = dirname(__FILE__).'\\fonts\\';//修改字体的路径从原来的/fonts/ 改为 \\fonts\\
如果没修改在windows下会报下面的错误
解决中文问题:
如果你的文件编码为utf-8,修改方法如下
方法一:
找到
elseif( $aFF === FF_SIMSUN) {
// Do Chinese conversion
if( $this->g2312 == null ) {
include_once 'jpgraph_gb2312.php' ;
$this->g2312 = new GB2312toUTF8();
}
return $this->g2312->gb2utf8($aTxt);
}
修改为
elseif( $aFF === FF_SIMSUN) {
// Do Chinese conversion
/*
if( $this->g2312 == null ) {
include_once 'jpgraph_gb2312.php' ;
$this->g2312 = new GB2312toUTF8();
}
return $this->g2312->gb2utf8($aTxt);
*/
return $aTxt;
}
方法二:在程序中修改
$title="流量图";
$title = iconv("UTF-8", "gb2312", $title);
$graph->title->Set($title);
$title = iconv("UTF-8", "gb2312", $title);
$graph->title->Set($title);
注:
jpgraph默认显示汉字时是把汉字编码认为gb2312,转化为utf-8以后再显示。
这样的话,如果你的文件编码是gb2312,SetFont方法的第一个参数为FF_SIMSUN即可。
如果你是utf-8编码你还需要先把汉字编码转化为gb2312,这样你的汉字才可以正常显示。
这样的话,如果你的文件编码是gb2312,SetFont方法的第一个参数为FF_SIMSUN即可。
如果你是utf-8编码你还需要先把汉字编码转化为gb2312,这样你的汉字才可以正常显示。
代码如下:
<?php
/**
* 使用jpgraph生成3D饼图
*
*/
include 'src/jpgraph.php';
include 'src/jpgraph_pie.php';
include 'src/jpgraph_pie3d.php';//引用3D饼图pieplot3D对象所在的类文件
$result = array(5,8,11,1,1,1);
$vote_content = array("张三","丽丽","lili","张三","丽丽","lili");
$title = '标题';
$graph = new PieGraph(500,245);//创建图像
$graph->SetShadow();//创建图像阴影
$graph->tabtitle->SetFont(FF_SIMSUN,FS_BOLD,14);//设置标题字体
$graph->tabtitle->Set($title);//输出标题
$graph->title->SetColor("darkblue");//定义标题颜色
$p1 = new PiePlot3D($result);//创建图像
//$p1->SetTheme("water");//控制图像的颜色
//$p1->SetCenter(0.4);//设置图像位置
//$p1->SetSize(0.4);//设置图像的大小
//$p1->SetHeight(20);//设置饼图的高度
//$p1->SetAngle(45);//设置图像的倾斜角度
//$p1->Explode(array(5,40,10,30,20));//控制饼图的分割
//$p1->value->SetFont(FF_SIMSUN,FS_BOLD,20);//设置字体
/* 注释文字 */
$p1->SetLegends($vote_content);
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD);//设置注释文字字体
$graph->legend->Pos(0.05,0.3,"right","center");//控制注释文字的位置
$graph->legend->SetShadow();//边界
$graph->legend->SetLayout(LEGEND_VERT);//设置图例样式和位置
$graph->Add($p1);//添加数据
$graph->Stroke();//生成图像
0 0
- PHP 绘图——使用jpgraph绘图
- PHP绘图入门以及JPGraph库的使用
- PHP自学之路---报表及绘图技术(jpgraph库使用,Linux安装及配置说明)
- php 绘图
- php绘图
- php绘图
- jpgraph绘图库的安装与配置
- JavaScript基础——使用Canvas绘图
- Python下使用OpenCV——绘图
- Qt绘图——QPixmap的使用
- 绘图类—Graphics
- openCV—基本绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- ubuntu12.04 thinkpad的touchpad设置
- 服务器和客户端笔记
- cocos2dx 获取点击坐标
- 快速排序
- android中dumpsys命令用法详解
- PHP 绘图——使用jpgraph绘图
- http iOS
- 利用循环打印图形
- [欧拉回路+手动开栈] poj 1780 Code
- leetcode-Largest Rectangular Area in a Histogram
- UVA - 11044 Searching for Nessy
- Harvard statistics 110, video 8 note(random variables & their distribution
- 关于程序员成长的一点思考
- Hustoj (poj2104)线段树(划分树)