1.Phantomjs:

下载:https://phantomjs.org/download.html

PhantomJS官方地址:http://phantomjs.org/。

PhantomJS官方API:http://phantomjs.org/api/。

PhantomJS官方示例:http://phantomjs.org/examples/。

PhantomJS GitHub:https://github.com/ariya/phantomjs/

window:

添加的环境变量为:;D:\phantomjs\bin

phantomjs --version 测试版本提示版本说明安装成功

linux:

tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2

ln -s /var/chart/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/

ln -sf /var/chart/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs

方法一:(推荐使用)

①、用命令授权:ln -s /usr/echarts/phantomjs/bin/phantomjs /usr/bin/

②、在/usr/echarts/phantomjs/bin下执行chmod 777 phantomjs 给执行的权限

③、执行phantomjs –version或者phantomjs –v得到版本号则为成功

方法二:

①、在/usr/echarts/phantomjs/bin下执行chmod 777 phantomjs 给执行的权限

②、添加环境变量

命令:vi /etc/profile

在最后一行添加 export PATH=$PATH:/usr/echarts/phantomjs/bin

③、执行 source /etc/profile然后重启电脑shutdown -r now

export PATH=$PATH:/var/chart/phantomjs-2.1.1-linux-x86_64/bin

2、echarts-convert

下载:https://gitee.com/saintlee/echartsconvert

一个配合phantomjs,在服务端生成EChart图片的工具包。

echarts-conver参数

详见:https://gitee.com/saintlee/echartsconvert

-s或--server:开启服务监听,如果开启服务端,则-o不生效,这也就意味不能使用脚本命令生成图片;

-p或--port:端口号,只有-s启用时生效,改变监听端口号;

-o或--opt:ECharts的option,这里是json字符串,最外层不加引号;

    示例:{title:{text:'ECharts示例'},tooltip:{},legend:{data:['销量']},xAxis:{data:['衬衫','羊毛衫','雪纺衫','裤子','高跟鞋','袜子']},yAxis:{},series:[{name:'销量',type:'bar',data:[5,20,36,10,10,20]}]}

-t或--type:生成类型file或base64,file是生成图片,base64是生成Base64字符串;

-f或--outfile:文件输出路径,只有--type=file时生效,如果不指定,则在脚本目录下创建一个tmp文件夹,将图片以时间戳为名字,保存到tmp目录下;

-w或--width:生成的图片宽度,默认800像素;

-h或--height:生成的图片高度,默认400像素。

生成图片命令:

phantomjs F:\ws\export02\tools\echarts-convert.js -infile F:\ws\export02\tools\option.js -width 800 -height 800

作为server

只能生成简单echarts,返回图片base64

phantomjs /usr/echarts/echartsconvert/echarts-convert.js -s -p 6666

后台启动

nohup phantomjs /usr/echarts/echartsconvert/echarts-convert.js -s -p 9090 &

9090是端口号,echartsconvert默认端口也是9090

命令行

作为脚本使用生成本地图片,能生成较复杂echarts

phantomjs /app/echartsconvert/echarts-convert.js -o [echartsOption] -t file -f [filePath] [-w width] -h[height]

phantomjs /var/chart/echartsconvert-master/echarts-convert.js -infile /var/chart/option.js -width 800 -height 800 -outfile /var/chart/111.png

发现 -infile没有了,一下是我的一个成功生成的例子

E:\Desktop\chart\phantomjs-2.1.1-windows\phantomjs-2.1.1-windows\bin\phantomjs E:\Desktop\chart\echartsconvert-master\echartsconvert-master\echarts-convert.js -o {'grid':{'top':20,'right':20,'bottom':40,'left':40},'legend':{'type':'scroll','bottom':'0','left':'center'},'tooltip':{'trigger':'item'},'series':[{'name':'','type':'pie','radius':'50%25','avoidLabelOverlap':true,'itemStyle':{'borderColor':'#fff','borderWidth':2},'label':{'show':true,'formatter':'{b}{d}%25'},'emphasis':{'label':{'show':true,'fontSize':'13'}},'data':[{'name':'口腔设备','value':3,'pieCount':3},{'name':'消毒设备3.22%25','value':10,'pieCount':10},{'name':'医用电子仪器','value':31,'pieCount':31},{'name':'医用高频仪器设备','value':8,'pieCount':8},{'name':'激光仪器设备','value':10,'pieCount':10},{'name':'中医仪器设备','value':3,'pieCount':3},{'name':'手术急救设备','value':69,'pieCount':69},{'name':'体外循环设备','value':15,'pieCount':15},{'name':'医用磁共振设备','value':2,'pieCount':2},{'name':'医用X线设备','value':21,'pieCount':21},{'name':'临床检验分析仪器','value':34,'pieCount':34},{'name':'医用超声仪器','value':40,'pieCount':40},{'name':'物理治疗及体疗设备','value':8,'pieCount':8},{'name':'光学仪器及窥镜','value':45,'pieCount':45},{'name':'病房护理设备','value':4,'pieCount':4},{'name':'医用核素设备','value':1,'pieCount':1},{'name':'其他','value':26,'pieCount':26}],'top':-50}]} -t file -f E:\Desktop\chart\tmpfiles\1682063489594.png

以下记录一下学习过程的问题:

在option里如果出现 %,则执行会挂掉

需要将%替换为%25


转载:http://www.5180it.com/bbs/admin/1/126060.html