Help with running an example

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

Help with running an example

Post by Nathan » Tue May 04, 2004 2:09 pm

I am new to java and I have to use JFreeChart for an project i have to make and in need of some help :)

I have this little piece of code from the web

Code: Select all

import org.jfree.chart.*;
import org.jfree.data.*;

public class TheFuture {

    public static void main(String[] args) {

	XYSeries series = new XYSeries("Linux Users");
	series.add(1995, 0.5);
	series.add(2000, 3.0);
	series.add(2010, 20.0);
	series.add(2020, 50.0);
	XYDataset dataset = new XYSeriesCollection(series);

	JFreeChart chart = ChartFactory.createXYAreaChart(
	     "Linux Users",
	     "Year",
	     "Millions",
	     dataset,
             org.jfree.chart.plot.PlotOrientation.VERTICAL,


             true,
	     false,
             false);

	try {
	  ChartUtilities.saveChartAsJPEG(new java.io.File("TheFuture.jpg"), chart, 500, 300);
	} catch (java.io.IOException exc) {
	    System.err.println("Error writing image to file");
	}
    }
}
and i can comile it with:
javac -classpath jfreechart-0.9.18.jar;lib\jcommon-0.9.3.jar TheFuture.java

but I can not execute it,
when i do:
java -classpath jfreechart-0.9.18.jar TheFuture
i get the message
Exception in thread "main" java.lang.NoClassDefFoundError: TheFuture

Please advise

Thanks Nathan

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue May 04, 2004 9:45 pm

You need to add the current directory to your classpath. Use '-classpath .;jfreechart-0.9.18.jar;lib\jcommon-0.9.3.jar' rather than '-classpath jfreechart-0.9.18.jar'.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Nathan

Thanks

Post by Nathan » Wed May 05, 2004 9:03 am

Thanks a lot :D
Learned again something!!

jroch

Post by jroch » Fri May 07, 2004 5:14 pm

New to JFreeChart

Under Linux, I just cut/paste the extended classpath, but I keep having:

package org.jfree.chart does not exist
package org.jfree.data does not exist

What I did next is I compiled (I had to comment out all the JavaDoc parts in build.xml) but that didnt' change anything.

JRoch

Post by JRoch » Fri May 07, 2004 11:09 pm

I found out, it was just my path delimitators (not the same in Linux)!

It works now, I'm right in front of the beautiful graph from Nathan's example.

Thanks both!

Jacky11287

But I got the different error, hope can help me~~~

Post by Jacky11287 » Sat May 08, 2004 11:26 am

I try this sample:

Code: Select all

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFrame;

import org.jfree.data.DefaultPieDataset;

public class FirstJChart {

	public static void main(String[] args) 
	{
		// Creating Data Set
		DefaultPieDataset dataSet = new DefaultPieDataset();
		
		dataSet.setValue("Marcelo", 20);
		dataSet.setValue("Jacky", 33);
		dataSet.setValue("Johnny", 30);
		dataSet.setValue("Martin", 17);
		
		// Creating a pie chart
		JFreeChart chart = ChartFactory.createPieChart(
				"My first JFreeChart",
				dataSet,
				true,
				true,
				false				
		);
		
		// Displaying a pie chart
		ChartFrame chartFrame = new ChartFrame("My first Chart", chart);
		chartFrame.pack();
		chartFrame.setVisible(true);
	}
}
But I fail in running with the exception like:

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at org.jfree.chart.plot.PiePlot.<clinit>(PiePlot.java:309)
at org.jfree.chart.ChartFactory.createPieChart(ChartFactory.java:201)
at FirstJChart.main(FirstJChart.java:34)
Exception in thread "main"

What's wrong with my classpath settings? I can pass the compliation phrase~~~~

Thanks

rose1

Re: Help with running an example

Post by rose1 » Tue May 11, 2004 8:52 am

But when I impile the program, lots of errors turn up, examples:
F:\dlhngr\iReport\iReport0.2.3\mypage\org\jfree\chart\ChartFactory.java:169: cannot resolve symbol
symbol : class Layer
location: package ui
import org.jfree.ui.Layer;
^
F:\dlhngr\iReport\iReport0.2.3\mypage\org\jfree\chart\ChartFactory.java:170: cannot resolve symbol
symbol : class RectangleEdge
location: package ui
import org.jfree.ui.RectangleEdge;
^
and so on.
why? Wait for your help... Thank you very much!!

garv
Posts: 127
Joined: Wed Mar 31, 2004 3:44 pm
Location: Amsterdam, The Netherlands

Post by garv » Tue May 11, 2004 8:53 am

Classpath problem. Make sure the compiler can find the JCommon library.

Guest

Post by Guest » Tue May 11, 2004 10:27 am

I use JCreater Pro , I have import JCommon.jar in it through JDK Profiles.

rose1

Post by rose1 » Tue May 11, 2004 10:27 am

I use JCreater Pro , I have import JCommon.jar in it through JDK Profiles.

garv
Posts: 127
Joined: Wed Mar 31, 2004 3:44 pm
Location: Amsterdam, The Netherlands

Post by garv » Tue May 11, 2004 11:34 am

Hmm. Maybe you have an incompatible version of JCommon? What version of JFreeChart are you using?

All JCommon versions can be downloaded here:
http://sourceforge.net/project/showfile ... e_id=40079

rose1
Posts: 2
Joined: Tue May 11, 2004 10:36 am

Post by rose1 » Wed May 12, 2004 2:06 am

I use version 0.8.16 of JFreeChart.
Please tell me where they should place and ClassPath how to set .

http://sourceforge.net/project/showfile ... e_id=40079[/quote]

rose1
Posts: 2
Joined: Tue May 11, 2004 10:36 am

Post by rose1 » Wed May 12, 2004 3:36 am

Thank you, garv.
The problem has been sovled by me.It was because of the version and classpath . You are right. JCommon should place in lib and JFreechart is the same layer with lib.
Example: C:\java\jfreechart-0.9.16\jfreechart-9.16.jar;
C:\java\jfreechart-0.9.16\lib\jcommon-0.9.1.jar.
That's OK. Thank you !

Locked