#### Contents

Introduction
How to insert a dynamic chart into a JSP page?
Sample Code
Where is the SwiffChart.jar located?

## Introduction

Swiff Chart Generator offers you the ability to rapidly incorporate dynamic charts into your JSP pages. To do so, you simply have to install Swiff Chart Generator on your Web Application Server machine and publish along with your JSP pages the complementary Jar archive named SwiffChart.jar installed with the product.

## How to insert a dynamic chart into a JSP page?

To insert a dynamic chart into a JSP page, follow the steps below:

- Publish the JAR archive named SwiffChart.jar in the appropriate location on your Web Application Server to make it accessible by your JSP page. This location depends on the specifications of your Web Application Server. Refer to the corresponding documentation for more information.
  To retrieve the SwiffChart.jar file, see Where is the SwiffChart.jar located?.
- Add the following <%@page import%@> JSP tag on top of your JSP page:

      <%@ page import="com.globfx.swiffchart.SwiffChart" %>

  see code sample
- Create a new SwiffChart object with the full pathname of the Swiff Chart Generator installation directory. This will enable the SwiffChart object to run the Swiff Chart engine installed on the server.

      String installation_dir= "C:\\Program Files\\GlobFX\\Swiff Chart Generator 4";
      SwiffChart chart= new SwiffChart(installation_dir);

  see code sample
  On Windows platform, Swiff Chart Generator installation directory is usually C:\Program Files\GlobFX\Swiff Chart Generator 4, whereas on Unix platform it is ususally /usr/local/SwiffChart
- Initialize the so-created SwiffChart object by calling the SetServletInfo and SetDocumentRoot methods with the 3 following parameters as shown in the code below:
  1. the response object (these are default global variables of the JSP page)
  2. the request object (these are default global variables of the JSP page)
  3. the Web Application Server document root directory (ie the full real pathname of the directory where the Web Application Server root is located).

      String web_root= "C:\\tomcat\\webapps\\ROOT";
      chart.SetServletInfo(request,response);
      chart.SetDocumentRoot(web_root);

  see code sample
- The SwiffChart object is now initialized and can be manipulated by calling the methods offered by the Swiff Chart Generator API. See the Reference manual for more information about the API. The JSP code sample below illustrates the common use of the Swiff Chart Generator API in a JSP page.

Important Note: Make sure that all the steps detailed above are fully completed before running your JSP page. If these parameters are not set with the correct values, the chart generation will fail. Furthermore, the chart object should be released with the Release() method after use.

## JSP Sample Code

The following JSP sample code illustrates the use of Swiff Chart Generator in a JSP page. This code is cross-platform, only the various pathnames must be modified.

    <%@ page import="com.globfx.swiffchart.SwiffChart" %>
    <%
      // Prior to any chart object instanciation, you must specify the full pathname of Swiff Chart Generator
      // installation directory as well as the full pathname of the Web Application Server root directory.
      String installation_dir= "C:\\Program Files\\GlobFX\\Swiff Chart Generator 4";
      String web_root= "C:\\tomcat\\webapps\\ROOT";

      // Create a new Swiff Chart object
      SwiffChart chart= new SwiffChart(installation_dir);

      // JSP Init
      chart.SetServletInfo(request,response);
      chart.SetDocumentRoot(web_root);

      String sep= ";";
      boolean ignoremultseparators= true;
      chart.SetSeparators(sep, ignoremultseparators);

      // Fill the categories
      String categories= "Q1" + sep + "Q2" + sep + "Q3" + sep + "Q4";
      chart.SetCategoriesFromString(categories);

      // Fill the first series named "Sales Y1"
      String series1= "12" + sep + "11" + sep + "6" + sep + "9";
      chart.SetSeriesValuesFromString(0, series1);
      chart.SetSeriesCaption(0, "Sales Y1");

      // Fill the second series named "Sales Y2"
      String series2= "23" + sep + "12" + sep +  "8" + sep + "11";
      chart.SetSeriesValuesFromString(1, series2);
      chart.SetSeriesCaption(1, "Sales Y2");

      // Set the chart title
      chart.SetTitle("Financial Results");
      chart.SetSubtitle("(Values in M$ - Year to year results)");

      // Apply a Column style
      // The chart type is stored in the style file (*.scs)
      // Here the selected style is the predefined column style "SanFrancisco"
      chart.LoadStyle( "column/SanFrancisco" );

      chart.SetLooping( false );

      String chart_res= chart.GetHTMLTag();

      // Release the chart object
      chart.Release();
    %>

    <H1>Column Chart</H1>
    <br><% out.println(chart_res); %>

What you will obtain

## Where is the SwiffChart.jar located?

The SwiffChart.jar archive is located in the Swiff Chart Generator installation directory:

    <install dir>/resources/java/SwiffChart.jar

where <install dir> is Swiff Chart Generator installation directory, usually C:/Program Files/GlobFX/Swiff Chart Generator 4/ on windows and /usr/local/SwiffChart for Unix.