Nodejs with PHANTOMJS highcharts background generation chart

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.