一、所需工具
1、phantomjs
2、EChartsConvert
二、Maven依赖
org.freemarker
freemarker
2.3.28
org.apache.httpcomponents
httpclient
4.5.7
com.alibaba
fastjson
1.2.56
三、运行EchartsConvert
1、安装phantomjs、EchartsConvert
解压 phantomjs-2.1.1-windows.zip 和 saintlee-echartsconvert-master.zip
2、命令行输入指令
命令行输入 -s -p
笔者没有配置环境变量,完整输入为
C:\Users\Administrator\Desktop\phantomjs-2.1.1-windows\bin>phantomjs C:\Users\Administrator\Desktop\echartsconvert\echarts-convert.js -s -p 6666
显示echarts-convert server start success. [pid]=10364表明启动成功
四、java代码
1、结构
image.png
2、工具类
Http工具类
package com.mosband.genecharts.util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUti