ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  ChartDirector Applet
Posted by Paulo Barroso on Dec-12-2007 19:08
Hi Peter,

We recently purchased the ChartDirector for JSP/Java.
Now we are doing some tests with the product.
First of all, we tested a sample Java program producing a bar chart.
For compiling and execute we used the commands below:

D:\\ChartDirector\\javademo>javac -classpath "ChartDirector_s.jar;." simplebar.java
D:\\ChartDirector\\javademo>java -classpath "ChartDirector_s.jar;." simplebar

Everything worked fine and the graph was produced.
After that we want to produce a bar chart made by an applet.
For doing that we used an sample applet code posted by you in this Forum (Jan-31-2005).  The code is shown at the end of this text:
The command used used to compile the applet was:

javac -classpath "ChartDirector_s.jar;." ChartDirectorDemo.java

When we tried to execute we had a problem. This time we had in the Java Console the following message:

java.lang.NoClassDefFoundError: ChartDirector/ChartViewer
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
        at java.lang.Class.getConstructor0(Class.java:2699)
        at java.lang.Class.newInstance0(Class.java:326)
        at java.lang.Class.newInstance(Class.java:308)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:778)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:707)
        at sun.applet.AppletPanel.run(AppletPanel.java:361)
        at java.lang.Thread.run(Thread.java:619)

(... using the IE or the Firefox browsers the result is the same...)

The HTML used was:

<HTML>
<APPLET CODE = "ChartDirectorApplet.class" WIDTH = 300 HEIGHT = 300>
</HTML>

We are not using any Web Server. We opened this HTML file directly from the browser.
The CLASSPATH system variable is shown below:

D:\\ChartDirector\\javademo>echo %classpath%

.;D:\\DB2\\java\\db2java.zip;D:\\DB2\\java\\db2jcc.jar;D:\\DB2\\java\\sqlj.zip;D:\\DB2\\bin
;D:\\DB2\\java\\common.jar;D:\\ChartDirector\\javademo\\ChartDirector_s.jar;


Can you tell me what we are doing wrong?
Many thanks for any help.

Paulo



-------  SAMPLE APPLET CODE --------------------

import ChartDirector.*;
import javax.swing.*;

public class ChartDirectorApplet extends JApplet
{
public void init()
{
try
{
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}});
}
catch (Exception e)
{
System.err.println("createGUI didn't successfully complete");
}
}

private ChartViewer viewer;

private void createGUI()
{
viewer = new ChartViewer();

//The data for the bar chart
double[] data = {85, 156, 179.5, 211, 123};

//The labels for the bar chart
String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};

//Create a XYChart object of size 250 x 250 pixels
XYChart c = new XYChart(250, 250);

//Set the plotarea at (30, 20) and of size 200 x 200 pixels
c.setPlotArea(30, 20, 200, 200);

//Add a bar chart layer using the given data
c.addBarLayer(data);

//Set the x axis labels using the given labels
c.xAxis().setLabels(labels);

//output the chart
viewer.setImage(c.makeImage());

//include tool tip for the chart
viewer.setImageMap(c.getHTMLImageMap("clickable", "", "title='{xLabel}:
US${value}K'"));

setSize(viewer.getImage().getWidth(null), viewer.getImage().getHeight(null));

getContentPane().add(viewer);
}
}

  Re: ChartDirector Applet
Posted by Peter Kwan on Dec-13-2007 01:15
Hi Paulo,

You need to tell the browser where to find the ChartDirector classes. As according to Java documentation, you may specify the "ChartDirector_s.jar" using the archive attribute. This should be the same for any Applet. For example:

<applet codebase="." code="ChartDirectorApplet.class" archive="ChartDirector_s.jar" width=250 height=250></applet>

I think the java classpath environmental variable is not used by Applets. It would be a serious security issue if an Applet can run code in the Java class library in your system.

Hope this can help.

Regards
Peter Kwan

  Re: ChartDirector Applet
Posted by Paulo Barroso on Dec-13-2007 10:14
Hi, Peter.
You're correct. Everything is working fine now. Thanks for the Java lesson, for your quick response and for your kindness.
Cheers,
Paulo