jpgraph绘制图表
发表日期:2010.06.02
jpgraph绘制图表
昨天看咯php100上面的jpgraph的教程..
一直想跑一个表格出来…
其实大体的思路已经搞通..
首先想好你要绘制的图标是那一类
饼图,柱状图,雷达图之类的
因为每一类所对应的库文件
设置数据数组..包含你所需的图形示例,数据等等
进行对类实例化
设置图片大小,底色以及是否有阴影之类的.
添加标题,设置字体以及大小,颜色.
添加数据
添加标签
添加示例
然后合成到一个数组里面
在进行输出
基本上都是大同小异
关键的问题出现咯..
我是用win的系统来跑的…
本地测试是没有任何问题
但是上传到Linux下面的时候
先提示我没有中文字库
Font file /usr/share/fonts/truetype/simsue.ttf is not readable or does not exist
问虚拟主机,问为什么没有字库,回答是英文OS,没有中文字库
全部换成英文的
提示Font file /usr/share/fonts/truetype/van….ttf is not readable or does not exist
就是没有字库…
上jpgraph官方网站来看看..
6 3.6 I get an error “Font file … is not readable or does not exist”This error is caused by the inability of PHP/JpGraph to read the font file. This could have several reasons:
1. The file path or name is wrong and the file really doesn’t exist. Please check that the file and path (as shown in the error message) really exists.
2. If the file exists it might still not be possible for PHP to read the file due to permission problem. Please make sure that PHP can read a file in the TTF directory. This can be verified with the following short script
< ?php
// Change this defines to where Your fonts are stored
DEFINE("TTF_DIR","/usr/X11R6/lib/X11/fonts/truetype/");
// Change this define to a font file that You know that You have
DEFINE("TTF_FONTFILE","arial.ttf");
$f = TTF_DIR.TTF_FONTFILE;
if( file_exists($f) === false || is_readable($f) === false ) {
echo "FAIL: Can not read font file \"$f\".";
}
else {
echo "PASS: Successfully read font file \"$f\".";
}
?>
If the script reports FAIL then it must be investigated whether the file names or permissions are wrong
大体意思的就是要么没有那个字库要么没有那个权限.
因为虚拟主机用的是centos+cpanel..
刚好手头有台ubuntu的主机,大同小异吧
去找/usr/share/fonts/truetype下面看看有字库文件..
刚开始去google一下,发现基本上说的都没有任何作用.
那就自己写一个文件来看看该目录下面是否有字库文件并打印出来
以前有写过查询目录下文件的程序,调出来调试
print_r数组,array();空的,echo,也是空白
看看系统的errorlog..
PHP Warning: opendir(/usr/share/fonts/truetype) [function.opendir]: failed to open dir: Operation not permitted in /home/xxx/public_html/xxx.php on line 4
大概意思就是说没有权限来打开这个文件夹
真的是踏破铁鞋无觅处,柳暗花明又一村啊…
看看能不能找到字库文件的权限呢?
上ftp看权限,倒是有一个fontsconfig…但是里面的貌似都是/usr/share/fonts/default下面的
看来权限是绕不过去的…
怎么该怎么改
突然想起,其实自己的www文件夹不是拥有全部的权限吗…
上传字库到自己的www文件夹下面
进jpgraph.php里面设置,指定字库位置
Setup path for western/latin TTF fonts
Setup path for MultiByte TTF fonts (japanese, chinese etc.)
DEFINE(“TTF_DIR”,”/home/xxx/public_html/xxx/”);
DEFINE(‘MBTTF_DIR’,'/home/xxx/public_html/xxx/’);
上传文件看看能不能打开
PASS: Successfully read font file /home/xxx/public_html/xxx/simsun.ttf
Good.
上传生成图片的文件,打开,perfect…
成功咯..
结论就是,其实有的时候绕进去咯,及早绕出来,问题就解决掉咯.
换种话说,有些事情明知不可为,那就要从另辟路径才能柳暗花明又一村.

