main | documentation | examples | common questions | changes | licensing


Java Applets
Applets are small java programs embedded and executed in web pages. An applet tag tells the web browser to download a set of java classes from the web server and execute the applet. To run applets, do the following:

  1. copy the chart.jar file found in the EasyCharts distribution to your web server, preferrably to the directory where your applet page is.

  2. set your applet tag to

    <applet code="com.objectplanet.chart.ChartApplet"
     archive="chart.jar" width=300 height=200>
    <param name="chart" value="bar">
    <param name="sampleValues" value="10,20,30,40,50">

Then the client browser can access your applet and the chart.jar file is loaded from the web server to the client and started automatically.

All the chart parameters are defined using the applet param tag

<param name="parameter" value="parameter value">

See the parameter list for details.
BarChart parameters
LineChart parameters
PieChart parameters

The default image format generated is a 256 color PNG image. This is very similar to gif images, but has no patent restrictions with it. You can also have truecolor PNG images and jpeg images.


If you can not or do not want to have the chart.jar file in the same directory as your applet files you can put them in another directory on your web server (needs to be accessible to the clients) and use a relative (or absolute) path in your archive tag.


Java Applications
When you compile and run a java application the compiler or java runtime needs to know where the EasyCharts java classes are.

If you are using the Java Developers Kit (JDK) version 1.1 add the chart.jar file to your CLASSPATH.

set CLASSPATH=%CLASSPATH%;c:\EasyChars\chart.jar

If you are using JDK 1.2 or newer place the chart.jar file in the jre\lib\ext directory of the JDK directory.

If you are using Microsoft Visual J++ or any other development environment, import the chart.jar file into the environment so the compiler and runtime will find it.

Then you need to import the chart package in your java application.

// file:
import com.objectplanet.chart.*;
import java.awt.*;
public class Bar {

   public static void main(String[] argv) {
      BarChart chart = new BarChart();
      double[] values = new double[] {10,20,30,40,50};
      chart.setSampleValues(0, values);

      Frame f = new Frame();
      f.add("Center", chart);

Now compile the java program and run it (JDK).

java Bar

All the chart parameters are accessed using setter and getter methods pairs in the following general format

parameterValue = chart.getParameterName();

See the parameter list for details.
BarChart parameters
LineChart parameters
PieChart parameters

Java Servlets
To avoid some of the problems with downloading and running applets in web browsers such as missing java virtual machines, compatibility, and printing issues, you can instead generate the charts as jpeg or gif images on the server and send the image to the web browser.

To do this you need to install an application server that supports Java(tm) Servlets or JavaServer Pages(tm). One such application server is the Tomcat server which you can download here. Follow the installation instructions that comes with the package.

Then add the chartServer.jar file to your CLASSPATH or application server according to its instructions. Then start the application server.

You can now access the servlet using a standard html image tag:

<img src="http://server_name:8080/servlet/com.objectplanet.chart.ChartServlet?

<img src="http://server_name:8080/servlet/com.objectplanet.chart.ChartServlet?

<img src="http://server_name:8080/servlet/com.objectplanet.chart.ChartServlet?

This will generate the chart on the server, and return it to the client as a standard jpeg image. This image can then be saved to the disk, it also prints fine using any web browser that supports jpeg images.

All the chart servlet parameters are set using parameter=value pairs with an & sign used as a parameter delimiter

parameterName=value&anotherParameterName=another value

The servlet can also load it's data from a URL, using the data parameter.

<img src="http://server_name:8080/servlet/com.objectplanet.chart.ChartServlet?

See the parameter list for details.
BarChart parameters
LineChart parameters
PieChart parameters

If you want to generate other image formats you can use another image encoder by extending the ChartServlet class and overriding the encodeChartImage() method.

If you want to use the GifEncoder from ACME, do the following:

  1. Download the ACME GifEncoder
  2. Add the ACME packages to your CLASSPATH or java runtime environment
  3. Extend the ChartServlet class and override the encodeChartImage() method

    import com.objectplanet.chart.*;
    import Acme.JPM.Encoders.*;
    import javax.servlet.*;
    import java.awt.*;

    public class GifChartServlet extends ChartServlet
       public void encodeChartImage(Image image, OutputStream out,
       ServletResponse res) throws IOException
          // set the response type to a gif image
          // create a gif image and send it to the client
          GifEncoder encoder = new GifEncoder(image, out);

  4. Compile and make sure the class is available to your java runtime
  5. Call the servlet:
    <img src="http://server:8080/servlet/GifChartServlet?sampleValues=10,20,30,40,50">

Copyright (C) 1998-2010 ObjectPlanet, Inc.
phone (+47) 2233 3360 fax (+47) 2233 3361