Loading

Introduction

To setup a private export server in Java, you will need the official J2EE export handler provided in the FusionCharts package. The export handler will provide the necessary files to configure the export server. It will handle all requests sent by the user for exporting and generate the chart in the requested format.
The J2EE export handler is dependent on two external modules, namely, Inkscape and ImageMagick. These two need to be downloaded and installed separately on the same server.

How does it work?

  • A chart is rendered in the browser.

  • When the export to image/PDF option is selected, the chart generates the SVG string that represents the current state and sends to the export server.

  • The export server captures the SVG string.

  • The export server invokes a system call, triggering Inkscape to convert FusionCharts generated SVG string (which is passed to the server side script over AJAX) to PDF, PNG and SVG. However, Inkscape still has a limitation of generating a JPG file. Hence, ImageMagick is used to create the JPG files.

  • The export handler either writes the image or PDF to disk, based on the configuration provided by chart, or streams it back to the user as a download.

Installation

  • Setup a Windows/Linux based server with administrative access to install the export handler. This is particularly important, if you are using a shared hosting service for your web server.

  • Install both Inkscape and ImageMagick as they are necessary dependencies for the J2EE export handler to work.

  • Copy files from the FusionCharts J2EE Export Handler to the server.

  • Add the following servlet mapping in your application’s web.xml:

<servlet>
    <display-name>FCExporter</display-name>
    <servlet-name>FCExporter</servlet-name>
    <servlet-class>com.fusioncharts.exporter.servlet.FCExporter</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>FCExporter</servlet-name>
    <url-pattern>/JSP/ExportExample/FCExporter</url-pattern>
</servlet-mapping>
  • Modify the url-pattern as per your application needs.

  • Set the path to the folder where the generated image is to be saved in server in fusioncharts_export.properties file inside the Classes directory.

  • Only for Windows Environment: Configuration of Inkscape and ImageMagick path. Open fusioncharts_export.properties file present in the Classes directory and make the following changes:

# Please specify the path to a folder with write permissions
# The exported image/PDF files would be saved here (for Linux based server SAVEPATH should be changed to relative or absolute path accordingly)
SAVEPATH = /JSP/ExportExample/ExportedImages/

# This constant HTTP_URI stores the HTTP reference to
# the folder where exported charts will be saved.
# Please enter the HTTP representation of that folder
# in this constant e.g., http://www.yourdomain.com/images/
HTTP_URI = http://localhost:8081/ExportHandler/JSP/ExportExample/ExportedImages/

# OVERWRITEFILE sets whether the export handler would overwrite an existing file
# the newly created exported file. If it is set to false the export handler would
# not overwrite. In this case if INTELLIGENTFILENAMING is set to true the handler
# would add a suffix to the new file name. The suffix is a randomly generated UUID.
# Additionally, you can add a timestamp or random number as additional prefix.
FILESUFFIXFORMAT = TIMESTAMP
OVERWRITEFILE = false
INTELLIGENTFILENAMING = true

# Set the path of Inkscape here(Only for Windows)
INKSCAPE_PATH = C:\\Program Files (x86)\\Inkscape

# Set the path of ImageMagick here(Only for Windows)
IMAGEMAGICK_PATH = C:\\Program Files\\ImageMagick-6.9.0-Q16

Inkscape:

Inkscape is an open source vector graphics editor. What sets Inkscape apart is its use of Scalable Vector Graphics (SVG), an open XML-based W3C standard, as the native format. Inkscape has a powerful command line interface and can be used in scripts for a variety of tasks, such as exporting and format conversions. For more details, click here.

ImageMagick:

ImageMagick is a free and open-source software suite for displaying, converting, and editing raster image and vector image files. The software mainly consists of a number of command-line interface utilities for manipulating images.
For further details, click here.

Configuring the export server

To use the private export server, the following attributes need to be configured correctly in the chart.

Attribute Name Description

exportEnabled

Set value to 1 to enable exporting for the chart.

exportAtClient

Set value to 0 to enable export via a Private Export Server.

exportHandler

Set to absolute path of the export handler e.g. http://www.example.com/JSP/ExportExample/FCExporter.

exportAction

Set value to save to store the exported file on the private export server itself. Set to download to send the file back to the user (client) for download.

Top