Shell-command FusionCharts to render as image (using PhantomJS), bye bye Web Browser!
========
./phantomjs controller.js pathXMLDataFile.xml
- Create and save chart as images at command line sans, Web Browser
- Choose form JPG, PNG or GIF
- Create high resolution chart images by magnifying the charts without distortion
- Create thumbnail view of charts
- Download and Install PhantomJS
- Download FusionCharts Suite XT
- Create a folder and place PhantomJS binary in it (in case you have not set PhantomJS in path)
- Get
FusionCharts.js
,FusionCharts.HC.js
,FusionCharts.HC.Charts.js
,FusionCharts.HC.PowerCharts.js
,FusionCharts.HC.Widgets.js
,FusionCharts.HC.Maps.js
,jquery.min.js
from FusionCharts Suite XT Download Pack - Get desired FusionMaps XT map definition file, for example,
FusionCharts.HC.World.js
from FusionCharts Suite XT download pack. - Put all the above mentioned files in a folder
- Copy
control.js
andview.html
from this repository - Create an XML file that contains data and configurations for one or more chart/map/gauge
- Go inside the folder using commandline/terminal
- Execute!
./phantomjs controller.js pathXMLDataFile.xml
You can try the ready-to-use example provided here:
phantomjs controller.js SampleData.xml
phantomjs control.js XMLPath [CaptureDelayInMilliseconds] [ZoomFactor]
A small example XML:
<app outputFolder='chartImages/' captureDelayMs='200' outputType='png'>
<visualization type='sparkline' width='300' height='25' outputFilename='cisco-stock'>
<chart caption='Cisco' palette='1' canvasLeftMargin='110'>
<dataset>
<set value='38.42' />
<set value='41.43' />
<set value='34.78' />
<set value='40.67' />
<set value='44.12' />
<set value='38.45' />
</dataset>
</chart>
</visualization>
<visualization type='pie2d' width='500' height='400' outputFilename='sales-contrib'>
<chart caption='Sales contribution' >
<set value='4034355' label='Alt' />
<set value='1202300' label='For' />
<set value='800000' label='Chh' />
</chart>
</visualization>
</app>
-
<app>
is the root node -
<app>
may have the following configuring attributes:outputType
- Image format (it can bejpg
,png
, orgif
, default isjpg
)outputFolder
- Path where output files will be stored, make sure to add a/
at the end. If not specified, all output files will be stored in the the folder where the application is running)captureDelayMs
- A minimum delay in milliseconds is required for JavaScript to breath (default is300
)zoom
- It the magnification factor as number. Default is1
which means100%
. Thus,0.1
will reduce the image to10%
whereas10
will magnify the image10 times
the original.
-
Each chart is defined through
<visualization>
node, where this node need the following attributes:
- A
<visualization>
node must have a single<chart>
or<map>
node. This<chart>
or<map>
contains the data for the chart, map or gauge as per standard FusionCharts XML specifications for the particular chart, map or gauge.
- Microsoft Windows
- Apple Mac OS X
- Linux
- Converting individual chart to PDF is an issue due to a limitation of PhantomJS
- Can be programmed to batch export
- Can provide Base64 encoded image data as string for advanced use like email inline attachment
- Can configure PDF paper like orientation, paper size, border
- Can be set to work as a standalone export server
- Pretty soon phantomJS v2 will arrive with more robust webkit and more features
- v0.0.9.2 - 2013-05-24
Sudipto Chudhury
Copyright (C) 2013 Sudipto Choudhury (mail@sudipto.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Footnotes
-
http://docs.fusioncharts.com/charts/?Introduction/ChartList.html ↩
-
http://docs.fusioncharts.com/widgets/?Introduction/ChartList.html ↩
-
http://docs.fusioncharts.com/powercharts/?Introduction/ChartList.html ↩
-
http://docs.fusioncharts.com/maps/?introduction/MapsList.html)
width
- in pixels without 'px' suffixheight
- in pixels without 'px' suffixoutput
- File name (without the extension)