Simple sharing, the background using Nodejs combined with Highcharts, phantomjs the method of generating report pictures. This is mainly applied in Daily Mail.
Mainly refer to the following information:
- Http://www.highcharts.com/component/content/article/2-news/52-serverside-generated-charts#phantom_usage
- Https://bitbucket.org/ariya/phantomjs/downloads
- HTTPS://GITHUB.COM/HIGHSLIDE-SOFTWARE/HIGHCHARTS.COM/TREE/MASTER/EXPORTING-SERVER/PHANTOMJS this entire catalogue needs to be downloaded.
The key is to use PHANTOMJS to simulate the browser environment, which is a green program that does not need to be installed. Pro-Test OK on Win7 and 64bit Linux.
Then, presumably we need to deploy an environment like this (code address Https://github.com/kenkozheng/HTML5_research/tree/master/NodeJS-Highcharts):
PHANTOMJS is a Linux version, and Phantomjs.exe is the Windows edition.
So under windows, we can write:
var process = require ("child_process");p rocess.exec (function (err, stdout, stderr) { Console.log (Err, stdout, stderr);});
Options1.json is the data we configure.
It is important to note that, under Linux, you need to change to exec ('./phantomjs .... Of course, the students who are familiar with Linux can ignore the nonsense I say.
Of course, in order to be more convenient to use, slightly modify the highcharts-convert.js, add an input parameter, directly into the data, without the need to read the file.
To avoid the question of whitespace quotes, here encode.
for(i = 0; i < system.args.length; i + = 1) { if(System.args[i].charat (0) = = = '-') {Key= SYSTEM.ARGS[I].SUBSTR (1, i.length); if(Key = = = ' InFile ' | | key = = ' Callback ' | | key = = ' Dataoptions ' | | key = = ' Globaloptions ' | | key = = ' Customcode ') { //get string from file Try{Map[key]= Fs.read (system.args[i + 1]). Replace (/^\s+/, "); } Catch(e) {Console.log (' Error:cannot find file, ' + system.args[i + 1]); Phantom.exit (); } } Else if(Key = = = ' Input ') {map[' infile '] = decodeuricomponent (system.args[i + 1]);//here is the modified part}Else{Map[key]= system.args[i + 1]; } } }
You can play it like this after you modify it:
var process = require ("child_process"); var data = { Xaxis: { categories: [' Jan ', ' Feb ', ' Mar ', ' Apr ', ' may ', ' June ', ' Jul ' ', ' 29.9 ', ' Sep ', ' Oct ', ' Nov ', ' Dec ' }, series: [{ data: [71.5], 106.4, 129.2, 144.0, 176.0
, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4
]} ]};p rocess.exec (
function
( Err, stdout, stderr) { Console.log (err, stdout, stderr);});
In addition, under Linux, you may also encounter problems with fonts that cannot be displayed after a picture is generated.
In the/usr/share/fonts/to fill in the corresponding font file (you can directly copy the windows of the past).
After copying the past, you need to fc-cache-fv a bit, refresh the system font cache.
Nodejs with PHANTOMJS highcharts background generation chart