Demos

Beginner's Guide

Charts / Gauges / Maps Guide

Customizing Charts

API

Integrating With Your Stack

Help

Loading

Introduction

To setup a private export server in Ruby on Rails, you will need to install the official RoR export handler in your project. The export handler will handle all requests sent by the user for exporting and generate the chart in the requested format.
The FusionCharts RoR 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

  • Add this line to your application’s Gemfile:
gem 'fusioncharts_exporter'
  • And then execute:
$ bundle
  • Install both Inkscape and ImageMagick as they are necessary dependencies for the RoR export handler to work.

  • The gem provides a generator to create the required configuration files and directories. Run the following command:

$ rails generate fusioncharts_exporter:install

This creates the following files and directories:
- config/fusioncharts_exporter.yml
- tmp/fusioncharts/

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.

Configuration

The following are the configurables to be modified as required in the config/fusioncharts_exporter.yml:

  • Set inkscape_path as the location of the Inkscape executable.

  • Set imagemagick_path as the location of the ImageMagick executable.

  • Set save_path as the location on the server where the image will be saved.

Mount the application

You will have to specify the end point of the export server. In order to do this, you will have to mount the export handler to your rails application. Add the following lines in config/routes.rb:

mount FusionchartsExporter::Engine, at: "<path>"

For example, if you want your export server hosted at http://example.com/export, then add the following lines:

mount FusionchartsExporter::Engine, at: "export"
Top