Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

For business scenarios, users will have reports generated by corresponding user portraits every month or every day. Word needs to introduce Echarts charts, and data is analyzed in real time. Therefore, it is necessary to create corresponding Echarts data charts before exporting word report, so as to write pictures into Word documents. The background needs to actively generate echarts data charts according to the data and store them in a certain address or file service. When word documents are exported, images generated by real-time Echarts data are introduced in the charts to export and watchCopy the code

Implementation article: Java background to generate Echarts charts and save images

Echarts is generated by CMD calls using echarts-convert1.js and Phantomjs-2.1.1, which uses the Phantomjs tool and echarts-convert.js

Download link:

Link: pan.baidu.com/s/1NX9pf77S… Extraction code: WLI7

However, some problems were encountered during the testing process:

1. Installation of PhantomJS tool

Download PhantomJS

This is the official website download address, but in the above Baidu cloud disk should have, but it is Windows, the official website respectively provided Windows, Mac, and Linux installation package, according to their own needs to download. After downloading, unzip it to a folder that is easy to find, open and find phantomjs.exe in the bin folder, click Run, and the following interface appears, indicating that the installation is successful and you can use it.

2. Environment configuration

Find phantomjs.exe in the bin file and copy the folder path, for example, I am: C:\Users\Administrator\Desktop\me\ Reference \ Phantomjs-2.1.1-windows \bin

Then open the computer’s properties interface and follow the following instructions:

Open the environment variable to find the path property

Add the bin address we just pasted to path

Then save, and the environment variable is ready. Open a CMD window to verify: Type Phantomjs

It’s nice to see what’s in the red box

3. Development issues

When I was configuring the environment, AN error occurred while executing CMD in Java

Java.io. IOException: Cannot run Program “PHANtomjs “: CreateProcess Error =2, the specified file Cannot be found

The problem is that the current environment without this command, I in the CMD command is executed Java can generate images to a specified address, I wonder if the Java environment configuration update, finally ruled out the test or is invalid, but restart, that execution success, when using a development program environment may not be able to update the environment variables, need to restart the update.