Page 1 of 1
Java: JFreeChart with Swing Tutorial?
Posted: Sun Jan 07, 2007 12:46 pm
by Chris Corbyn
I need to make use of JFreeChart but the only documentation I seem to be able to find is the Generated API documentation which is great for reference once you have a basic grip on it I'm sure but you have to pay for the developer guide. I'd pay if I was using this in a commercial app but I'm not; it's a purely personal project
Anybody know of any learn-by-example type of tutorials for using JFreeChart in a Swing GUI?
http://www.jfree.org/
Posted: Sun Jan 07, 2007 2:48 pm
by aaronhall
Posted: Sun Jan 07, 2007 3:14 pm
by Chris Corbyn
Nice one thanks
Once I realised you can just attach the image to a JLabel as an icon using createBufferedImage() it was a bit easier to experiment. Sadly my Java knowledge is still in the "newbie" category so this project is a bit of learning experience for me.
Posted: Sun Jan 07, 2007 5:23 pm
by Chris Corbyn
Any idea how to work around this? I understand the error since double is an instance of Number, but the source is all compiled in the .jar archive. I'm using Java5. Perhaps this code worked ok in 1.4 maybe.
Code: Select all
w3style:~/java/SunTracker d11wtq$ javac SunTracker.java
./org/w3style/suntracker/grapher/AzimuthAltitudeGraph.java:14: reference to addValue is ambiguous, both method addValue(java.lang.Number,java.lang.Comparable,java.lang.Comparable) in org.jfree.data.category.DefaultCategoryDataset and method addValue(double,java.lang.Comparable,java.lang.Comparable) in org.jfree.data.category.DefaultCategoryDataset match
data.addValue(1.0, "Line 1", 1);
^
1 error
w3style:~/java/SunTracker d11wtq$
The issue is with the jfree package but I'm probably using it wrongly:
Code: Select all
package org.w3style.suntracker.grapher;
import java.awt.image.BufferedImage;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.chart.plot.PlotOrientation;
public class AzimuthAltitudeGraph
{
public BufferedImage getChartAsBufferedImage(int dimX, int dimY)
{
DefaultCategoryDataset data = new DefaultCategoryDataset();
data.addValue(1.0, "Line 1", 1);
//etc etc (just testing now)
JFreeChart chart = ChartFactory.createLineChart(
"My line chart",
"Azimuth",
"Altitude",
data,
PlotOrientation.HORIZONTAL,
true,
true,
false
);
BufferedImage image = chart.createBufferedImage(dimX, dimY);
return image;
}
}
Relevant API notes:
JFreeChart ChartFactory.createLineChart
DefaultCategoryDataSet (where problem is)
PlotOrientation
EDIT | Casting as (Number) fixes it but; Grrr..... I shouldn't have to do that should I?
