acomer - 2004-06-16

I have written the following code based on the
examples. chart1.png is created successfully, but chart2
fails with the following error:

de.progra.charting.EncodingException
at
de.progra.charting.ChartEncoder.createEncodedImage
(Unknown Source)
at
com.delta.mw.rvgestalt.chart.write_viewable_chart
(chart.java:24)
at com.delta.mw.rvgestalt.chart.main
(chart.java:174)
Caused by: java.lang.ClassCastException
at
de.progra.charting.CoordSystemUtilities.drawXAxisTicks
(Unknown Source)
at de.progra.charting.CoordSystem.paintDefault
(Unknown Source)
at de.progra.charting.CoordSystem.render
(Unknown Source)
at de.progra.charting.DefaultChart.render
(Unknown Source)
... 3 more

The source code follows.

Any idea?? Any help would be appreciated
Alex Comer

=================================

package com.delta.mw.rvgestalt;

import de.progra.charting.*;
import de.progra.charting.model.*;
import de.progra.charting.render.*;
import java.awt.*;
import java.io.*;
import java.util.*;

class chart {

public static void write_viewable_chart(DefaultChart c, String filename)
{
// Export the chart as a PNG image
try {

FileOutputStream fos = new FileOutputStream( filename );

ChartEncoder.createEncodedImage(fos, c, "png");

} catch(Exception e) {
e.printStackTrace();
}
}

public static DefaultChart create_chart1()
{
int[][] model = {{0, 100, 200000}}; // Create data array
double[] columns = {0.0, 1.0, 2000.0}; // Create x-axis values
String[] rows = {"DataSet 1"}; // Create data set title
String title = "A First Test"; // Create diagram title

// Create data model
DefaultChartDataModel data = new DefaultChartDataModel(model, columns, rows);

// Create chart with default coordinate system
DefaultChart c = new DefaultChart(data, title, DefaultChart.LINEAR_X_LINEAR_Y);

// Add a line chart renderer
c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(), data /* , RowColorModel.getInstance(data) */ ), 1);

// Set the chart size
int width = 640; // Image size
int height = 480;
c.setBounds(new Rectangle(0, 0, width, height));

return c;
}

public static DefaultChart create_chart2()
{
int[][] model = {{0, 100, 200000}}; // Create data array

Date[] columns = new Date[3];
columns[0] = new Date(2000, 1, 1, 0, 0, 0);
columns[1] = new Date(2002, 1, 1, 0, 0, 0);
columns[2] = new Date(2003, 1, 1, 0, 0, 0);

String[] rows = {"DataSet 1"}; // Create data set title
String title = "A First Test"; // Create diagram title

// Create data model
ObjectChartDataModel data = new ObjectChartDataModel(model, columns, rows);

// Create chart with default coordinate system
DefaultChart c = new DefaultChart(data, title, DefaultChart.LINEAR_X_LINEAR_Y);

// Add a line chart renderer
c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(), data /* , RowColorModel.getInstance(data) */ ), 1);

// Set the chart size
int width = 640; // Image size
int height = 480;
c.setBounds(new Rectangle(0, 0, width, height));

return c;
}

public static void main(String[] args){

DefaultChart c1 = create_chart1();
write_viewable_chart(c1, "chart1.png");
DefaultChart c2 = create_chart2();
write_viewable_chart(c2, "chart2.png");
}

};