ValueAxis - class cast exception

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

ValueAxis - class cast exception

Post by tony » Fri Aug 23, 2002 1:47 am

Hi,

I get a ClassCastException: com.jrefinery.chart.VerticalNumberAxis when I run this snipit.

I tried to get around this by declairing the parameter for the new XYPlot as a VerticalNumberAxis and a ValueAxis - with no luck. Am I missing something or is this a bug?

Also, how come you don't have a 0 param constructor for the HorizontalNumberAxis() ?

thanks,
Tony.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;

import com.jrefinery.chart.*;
import com.jrefinery.chart.entity.*;
import com.jrefinery.chart.event.*;
import com.jrefinery.chart.tooltips.*;
import com.jrefinery.chart.ui.*;
import com.jrefinery.data.*;

public class ChartDevel extends JFrame {

private ChartPanel chartPanel;
private JFreeChart chart;
private XYSeries series;
private XYSeriesCollection dataset;
private XYDataset data;
private XYPlot xyplot;
private ValueAxis domain;
//private VerticalNumberAxis domain;
private ValueAxis range;
//private HorizontalNumberAxis range;


public ChartDevel() {
super();
setBounds(250, 2, 600, 400);

range = new HorizontalNumberAxis("y");
domain = (ValueAxis)new VerticalNumberAxis();

data = new TheDataset();

xyplot = new XYPlot(data, domain, range);
chart = new JFreeChart(xyplot);

chartPanel = new ChartPanel(chart);

getContentPane().add(chartPanel);
setVisible(true);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

}//constructor

public static void main(String[] args) {
ChartDevel cd = new ChartDevel();
}

class TheDataset extends DefaultXYDataset {

public Number getXValue(int series, int item) {

return new Double(-10.0+(item/10.0));
}
public Number getYValue(int series, int item) {
if (series==0) {
return new Double(Math.cos(-10.0+(item/10.0)));
} else {
return new Double(2*(Math.sin(-10.0+(item/10.0))));
}
}
public int getItemCount(int series) {
return 200;

}
public int getSeriesCount() {
return 1;
}
public String getSeriesName(int series) {
if (series==0) {
return ""; // "y = cosine(x)";
} else if (series==1) {
return ""; //"y = 2*sine(x)";
}
else return "Error";
}
}//class TheDataset
}//class

David Gilbert

Re: ValueAxis - class cast exception

Post by David Gilbert » Fri Aug 23, 2002 6:50 am

You've mixed your horizontal axis and your vertical axis. The domain values are plotted against the horizontal axis, and the range values against the vertical axis.

Regards,

DG.

Locked