How to use JFreeChart Classes in an applet?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
bacchus

How to use JFreeChart Classes in an applet?

Post by bacchus » Fri Jan 10, 2003 4:27 pm

hi,all
I am a beginner of java programing and my english is poor . So I have many difficulties in using JFreeChart in applets. Can you give me a favor to master the skill? And,is there any example about applet in the src/com/jrefinery/chart/demo directory ?
Thank you all.
--Bacchus.

twist

Re: How to use JFreeChart Classes in an applet?

Post by twist » Fri Jan 10, 2003 6:05 pm

This is more simple than can You image it :-)

import java.awt.*;
import java.applet.*;

import com.jrefinery.data.DefaultPieDataset;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.Pie3DPlot;

public class Demo extends Applet implements Runnable {

public Demo()
{
}

public void init()
{
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("Java", new Double(43.2));
data.setValue("Visual Basic", new Double(10.0));
data.setValue("C/C++", new Double(17.5));
data.setValue("PHP", new Double(32.5));
data.setValue("Perl", new Double(12.5));

// create the chart...
JFreeChart chart = ChartFactory.createPie3DChart("Pie Chart 3D Demo 1", // chart title
data, // data
true // include legend
);
// set the background color for the chart...
chart.setBackgroundPaint(Color.white);
Pie3DPlot plot = (Pie3DPlot) chart.getPlot();
plot.setStartAngle(270);
plot.setDirection(Pie3DPlot.ANTICLOCKWISE);
plot.setForegroundAlpha(0.5f);
// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 370));
setLayout( new FlowLayout() );
add(chartPanel);
}

public void run() {
}

public void destroy() {
System.exit(0);
}
}//

David Gilbert

Re: How to use JFreeChart Classes in an applet?

Post by David Gilbert » Fri Jan 10, 2003 9:42 pm

There is a JFreeChartAppletDemo.java file in the com.jrefinery.chart.demo package. I had it running once upon a time, I imagine it should still work.

Just a couple of days ago I added the following demo to the website:

http://www.object-refinery.com/jfreechart/applet.html

If you view the source of the HTML for that page, you'll see what the <APPLET> tag should look like. I plan to write this up for the JFreeChart documentation.

Regards,

Dave Gilbert

Bacchus

Re: How to use JFreeChart Classes in an applet?

Post by Bacchus » Sat Jan 11, 2003 5:54 am

Thank you two firstly!
Then I still have some questions to bother you. ^_^

***********************************************************
to twist:
I can run the source you give me in Jbuilder 7,but when I embed this applet into a Html page ,it doesn't work. The IE browser tell me "exception:java.lang.ClassNotFoundException:com.jrefinery.data.DefaultPieDataset".How can I do?

The Html source is following:(I changed the name of the applet)
<applet
codebase = "."
code = "projfreechart.AppletTestDemo.class"
name = "TestAppletTestDemo"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>

**********************************************************
to Dave:
I can not see the applet in the page --"http://www.object-refinery.com/jfreechart/applet.html". The brower tell me "load:class com.jrefinery.chart.premium.demo.applet.Applet1 not found".
What's the matter?

**********************************************************
Thank you two again!
Regards,
Bacchus

twist

Re: How to use JFreeChart Classes in an applet?

Post by twist » Sat Jan 11, 2003 12:29 pm

hello

First method:
You have to create Demo.jar contains all necessary library: jcommon and jfreechart
Go to menu Wizards=>'Archive Builder', choose 'Archive type': Applet JAR, click Next, write Name: Demo
click Next, then pick up 'Always include all classes and resources'
click next and choose: 'Include required classes and all resources'. You should see over Library settings:
jfreechart Deps & resources
jcommon Deps & Resources
Finish
Build Demo.jar and add entry to applet tag like this:
<applet>
...
archive="Demo.jar"
...
</applet>

Second method:
put jfreechart.jar and jcommon.jar into Where_You_Have_J2SDK_Or_JRE\lib\ext\, should solve Your problem.

Bacchus

Re: How to use JFreeChart Classes in an applet?

Post by Bacchus » Mon Jan 13, 2003 7:04 am

to twist:
I hava builded a .jar file as you said in method one,but the problem is still existing. The change is the error message in IE became "exception:java.lang.ClassNotFoundException:java.awt.Paint".
I can see the IE has loaded the .jar file. And I can successfully view the html page included anothor applet which needs java.awt.* 'support.
I am so sorry for my stupid,but I really want to solve the porblem.
Can you help me again? Thank you!

Regards,
Bacchus.

David Gilbert

Re: How to use JFreeChart Classes in an applet?

Post by David Gilbert » Mon Jan 13, 2003 4:13 pm

This sounds to me like you are using the default JVM in Internet Explorer which I think is based on JDK1.1 (I don't know though, because I don't have Internet Explorer). There is a Java plug-in available that you can install to allow you to use applets that use a more recent version of Java - it's been many years since JDK 1.1 was "current".

Regards,

Dave Gilbert

Locked