- 使用的原因:
使用这个工具来生成报表图片。
- 工具大致原理:
phantomjs是phyon编写的一个无窗口浏览器,可以开启服务后可以执行,可以执行特定的js脚本。本工具自动集成了echarts的报表图片生成功能。
- 工具的安装:
3.1集成在管控系统的应用环境中。(以管控的应用的安装目录为起点)存放位置:
./eachartsutils. 内含三个子目录:分别为window,Linux的执行程序目录,图片生成脚本目录。对应目录结构如图:
3.2端口要求:需要单独申请phantomjs服务的端口,程序处理的默认端口:6666
3.3phantomjs在Linux下授权,建议对Linux的phantomjs程序 授权777
命令如下:chmod 777 phantomjs
3.4切换目录到eachartsutils下。执行以下命令,验证工具是否可以使用:
./phantomjs-2.1.1-linux-x86_64/bin/phantomjs ./echartsconvert/echarts-convert.js -s -p 6666
执行成功效果如图:
4.工具的环境不齐全处理:
找不到 libfontconfig.so.1
如图:(centos)
phantomjs -v
phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory
#解决方案
yum install fontconfig freetype2
如果出现phantomjs环境异常,可以参考
https://blog.csdn.net/liaonanfeng88/article/details/84941575
https://www.jianshu.com/p/e0c178747ddf
或谷歌,百度处理相关环境依赖问题。
公司使用的是华为云 操作系统是CentOS Linux release 7.6.1810 (Core)
我们需要在系统上安装相应的字体 然后重启插件phantomjs-2.1.1linux
yum install bitmap-fonts bitmap-fonts-cjk
图片中文若不显示:
安装字体 :SimSun,(Arial,微软雅黑)
参考:https://www.cnblogs.com/chengJAVA/p/5292014.html
另:或参照
在centos中执行:yum install bitmap-fonts bitmap-fonts-cjk
在ubuntu中执行:sudo apt-get install xfonts-wqy
另或者参照
https://www.cnblogs.com/hqqq/p/6219417.html