Home / Support / Swiff Chart Generator / Simple Pie Chart - Java Servlet
Knowledge Base

SAMPLE: Simple Pie Chart - Java Servlet

The information in this article applies to:

  • Swiff Chart Generator 2

This example illustrates how to generate a simple pie chart from a Java Servlet.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import com.globfx.swiffchart.SwiffChart;

public class SamplePie extends HttpServlet
  public void doGet( HttpServletRequest request,
                     HttpServletResponse response)
    throws IOException, ServletException
    PrintWriter out= response.getWriter();

      String installation_dir= "/usr/local/SwiffChart";

      SwiffChart chart= new SwiffChart();

      // Required: Specify Swiff Chart Generator installation directory

      // Required: Initialisation of the chart object

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

      // Fill the series and categories
      String categories= "USA" + sep + "Germany" + sep + "United Kingdom";

      String series= "45" + sep + "28" + sep + "16";

      chart.SetSeriesValuesFromString(0, series);

      // Set the chart title
      chart.SetTitle("Geographical Distribution");

      // Apply a Pie style
      // The chart type is stored in the style file (*.scs)
      // Here the selected style is the predefined pie style "Honolulu"
      String style = "pie/Honolulu";
      chart.LoadStyle( style );
      chart.SetWidth( 400 );
      chart.SetHeight( 200 );
      chart.SetLooping( false );

    catch( Exception e )
      out.println( e );


Keywords:Servlet JSP Java Pie Chart

Swiff Chart Generator