|
From: Lee F. W. <le...@st...> - 2003-05-06 09:05:44
|
Hi
I'm trying to update some code that worked fine when using the 0.6.0 version
of jCharts. However, now it doesn't and I'm having difficulty finding out
why. The error seems to have something to do with the LabelAxisProperties
and AxisProperties classes, but I can't be sure. The code attatched below
causes the following error:
java.lang.ClassCastException
at
org.jCharts.chartData.processors.AxisChartDataProcessor.processData(Unknown
Source)
at org.jCharts.axisChart.AxisChart.renderChart(Unknown Source)
at org.jCharts.Chart.render(Unknown Source)
at org.jCharts.encoders.BinaryEncoderUtil.render(Unknown Source)
at org.jCharts.encoders.PNGEncoder.encode(Unknown Source)
at org.jCharts.demo.swing.TestGraph.doWork(TestGraph.java:89)
at org.jCharts.demo.swing.TestGraph.main(TestGraph.java:108)
Exception in thread "main"
However, it works fine when I remove the axis code [replacing the line
"AxisProperties axisProperties = new AxisProperties(xAxis, yAxis)"
with "AxisProperties axisProperties = new AxisProperties()"] which is why I
suspect the LabelAxisProperties and AxisProperties are causing the trouble.
Can anyone see anything in my code that may be causing this trouble? Is this
a bug?
Appreciate any help you can offer.
Take care
Regards
Lee Francis
Here's the code. It creates a png file in the same directory as the class
file. I am using Sun's jdk 1.4.1 on Win2000. The jCharts version is 0.7.2,
but I also got the error with 0.7.0 beta 1 or 3 (?) releases.
import java.io.*;
import org.jCharts.*;
import org.jCharts.axisChart.*;
import org.jCharts.chartData.*;
import org.jCharts.encoders.*;
import org.jCharts.properties.*;
import org.jCharts.types.*;
public class TestGraph {
public void doWork() {
double[][] data = { {1, 3, 5, 7, 5, 8, 3, 5, 6, 7 } };
String[] xAxisLabels = { "0", "1", "2", "3", "4", "5", "6", "7", "8",
"9" };
String xAxisTitle = "x-axis";
String yAxisTitle = "y-axis";
String title = "title";
DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle,
yAxisTitle, title);
java.awt.Stroke stroke = new java.awt.BasicStroke(1,
java.awt.BasicStroke.CAP_ROUND,
java.awt.BasicStroke.JOIN_ROUND);
java.awt.Stroke[] strokes = { stroke };
java.awt.Shape[] shapes = { null };
ChartTypeProperties areaChartProperties = new
LineChartProperties(strokes, shapes);
java.awt.Paint[] paints = { java.awt.Color.RED };
String[] legendLabels = null ;
try {
AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data,
legendLabels, paints, ChartType.LINE, areaChartProperties);
dataSeries.addIAxisPlotDataSet(axisChartDataSet);
ChartProperties chartProperties = new ChartProperties();
LabelAxisProperties xAxis = new LabelAxisProperties();
LabelAxisProperties yAxis = new LabelAxisProperties();
xAxis.setShowGridLines(AxisTypeProperties.GRID_LINES_ONLY_WITH_LABELS);
yAxis.setShowGridLines(AxisTypeProperties.GRID_LINES_ONLY_WITH_LABELS);
AxisProperties axisProperties = new AxisProperties(xAxis, yAxis); //
causes the error
// AxisProperties axisProperties = new AxisProperties(xAxis, yAxis); //
works
LegendProperties legendProperties = null;
Chart chart = new AxisChart(dataSeries, chartProperties, axisProperties,
legendProperties, 400, 300);
String prefix = "jcharts_";
String suffix = ".png";
String dir = System.getProperty("user.dir");
File image = File.createTempFile(prefix, suffix, new File(dir));
String path = image.getCanonicalPath();
// save the chart to file
FileOutputStream fos = new FileOutputStream(path);
PNGEncoder.encode(chart, fos);
fos.close();
}
catch (PropertyException e) {
System.err.println("PropertyException " + e.getMessage());
}
catch (ChartDataException e) {
System.err.println("ChartDataException " + e.getMessage());
}
catch (FileNotFoundException e) {
System.err.println("FileNotFoundException " + e.getMessage());
}
catch (IOException e) {
System.err.println("IOException " + e.getMessage());
}
}
public static void main(String[] args) {
System.out.println("Starting");
new TestGraph().doWork();
System.out.println("Done");
}
}
In theory, there is no difference between theory and
practice. But, in practice, there is.
-- Jan L.A. van de Snepscheut
|