SAMPLE: Simple XY Line Chart - Java Servlet
The information in this article applies to:
- Swiff Chart Generator 2
This example illustrates how to generate a simple XY line chart from a Java Servlet.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.globfx.swiffchart.SwiffChart;
public class SampleXY extends HttpServlet
{
public void doGet( HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
PrintWriter out= response.getWriter();
try
{
String installation_dir= "/usr/local/SwiffChart";
SwiffChart chart= new SwiffChart();
// Required: Specify Swiff Chart Generator installation directory
chart.SetInstallDir(installation_dir);
// Required: Initialisation of the chart object
chart.SetServletInfo(request,response);
String sep= ";";
boolean ignoremultseparators= true;
chart.SetSeparators(sep, ignoremultseparators);
// Fill the first series named "Sales 2001"
String seriesx1= "0.5" + sep + "2.3" + sep + "8.9" + sep + "15.4";
String seriesy1= "8" + sep + "15" + sep + "2" + sep + "19";
chart.AddSeries();
chart.SetSeriesXValuesFromString(0, seriesx1);
chart.SetSeriesYValuesFromString(0, seriesy1);
chart.SetSeriesCaption(0, "Measure 1");
// Fill the second series named "Sales 2002"
String seriesx2= "0" + sep + "3" + sep + "5.2" + sep + "10.8";
String seriesy2= "23" + sep + "8" + sep + "12" + sep + "14";
chart.AddSeries();
chart.SetSeriesXValuesFromString(1, seriesx2);
chart.SetSeriesYValuesFromString(1, seriesy2);
chart.SetSeriesCaption(1, "Measure 2");
// Set the chart title
chart.SetTitle("Experimental Results");
// Apply a XY Line style
// The chart type is stored in the style file (*.scs)
// Here the selected style is the predefined XY line style "Honolulu"
String style = "xy/Honolulu";
chart.LoadStyle( style );
chart.SetWidth( 400 );
chart.SetHeight( 200 );
chart.SetLooping( false );
chart.SetOutputFormat("SWF");
chart.ExportAsResponse();
}
catch( Exception e )
{
out.println( e );
}
}
}
| References: |
| Keywords: | Servlet JSP Java XY Line |
