thanks, but ....

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
markusin
Posts: 11
Joined: Wed Nov 19, 2003 10:10 am

thanks, but ....

Post by markusin » Thu Nov 20, 2003 12:48 pm

First of all thanks for the answer
So I tried now to create the XYBarRenderer, but I still have some questions.
I created a JPanel, where I added the ChartPanel and in which Panel I inserted the JFreeCHart (see code).
So my class is: ReachGraphPanel.java

Code: Select all

public class ReachGraphPanel extends JPanel{

  private ChartPanel myChartPanel;
  private JFreeChart chart;
  private ReachGraphDataset data;
  private XYBarRenderer xyBR;


  private static final int SERIES =1;
  private int item = 0;
  private int pass = 0;



  private String xAxisLabel = "Objekt-ID";
  private ValueAxis  xAxis = new NumberAxis(xAxisLabel);
  private String yAxisLabel = "Erreichbarkeitsdistanz";
  private ValueAxis  yAxis = new NumberAxis(yAxisLabel);
  private String title = "Erreichbarkeitsgraph";


  // Konstruktor welcher eigentlich passen müsste.
  public ReachGraphPanel(OrderedFile of) {
    super();
    data = new ReachGraphDataset(of);

    // muss noch verbessert werden
    StandardXYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
    toolTipGenerator.generateToolTip(data, SERIES, item);

    // XYBarRenderer renderer = new XYBarRenderer(1.0, toolTipGenerator, null);
    XYBarRenderer renderer = new XYBarRenderer();
    XYPlot plot = new XYPlot(data, xAxis, yAxis, renderer);
    chart = new JFreeChart(title, plot);
    myChartPanel = new ChartPanel(chart);
    myChartPanel.setBackground(Color.BLUE);

    this.setLayout(new BorderLayout());
    this.add(myChartPanel);
    this.repaint();

  }
}
And the second class,
where I implemented the Interface XYDataset : ReachGraphDataset.java

Code: Select all

public class ReachGraphDataset implements XYDataset {
  // auf dieses OrderedFile wird dann zugegriffen
  private OrderedFile orderedFile;

  private static final int SERIESCOUNT = 1;
  private static final String SERIES = "First";
  private int itemCount;


  // Konstruktor
  public ReachGraphDataset(OrderedFile of) {
    this.orderedFile = of;
  }

  public Number getXValue(int series, int item) {
      return new Double((((Objekt)orderedFile.elementAt(item)).getX()));
  }

  public Number getYValue(int series, int item) {
      return new Double((((Objekt)orderedFile.elementAt(item)).getY()));
  }

  public int getSeriesCount() {
      return this.SERIESCOUNT;
  }
  public String getSeriesName(int series) {
      return "Sample " + series;
  }

  public int getItemCount(int series) {
      return orderedFile.size();
  }

  public static int getSERIESCOUNT() {
    return SERIESCOUNT;
  }

  public void addChangeListener(DatasetChangeListener datasetChangeListener) {
  }

  public void removeChangeListener(DatasetChangeListener datasetChangeListener) {
  }

  public DatasetGroup getGroup() {
    return null;
  }

  public void setGroup(DatasetGroup datasetGroup) {
  }
}
My first question:
Do I need to do more, to fill my dataset with the data imported from the Vector OrderedFile?
And the second question:
After compiling I got this java.lang.ClassCastException (where just the beginning of the whole exception code is relevant). What did I wrong? Did I forget to do something more with this Renderer?

Code: Select all

java.lang.ClassCastException

	at org.jfree.chart.renderer.XYBarRenderer.drawItem(Unknown Source)

	at org.jfree.chart.plot.XYPlot.render(Unknown Source)

	at org.jfree.chart.plot.XYPlot.draw(Unknown Source)

	at org.jfree.chart.JFreeChart.draw(Unknown Source)

	at org.jfree.chart.ChartPanel.paintComponent(Unknown Source)

	at javax.swing.JComponent.paint(JComponent.java:808)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JViewport.paint(JViewport.java:707)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JSplitPane.paintChildren(JSplitPane.java:1021)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paint(JComponent.java:817)

	at javax.swing.JLayeredPane.paint(JLayeredPane.java:552)

	at javax.swing.JComponent.paintChildren(JComponent.java:647)

	at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4778)

	at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4724)

	at javax.swing.JComponent.paint(JComponent.java:798)

	at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)

	at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)

	at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)

	at java.awt.Container.paint(Container.java:1309)

	at javax.swing.JFrame.update(JFrame.java:385)

	at sun.awt.RepaintArea.paint(RepaintArea.java:169)

	at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)

	at java.awt.Component.dispatchEventImpl(Component.java:3699)

	at java.awt.Container.dispatchEventImpl(Container.java:1623)

	at java.awt.Window.dispatchEventImpl(Window.java:1590)

	at java.awt.Component.dispatchEvent(Component.java:3480)

	at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)


	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

	at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Thanks for helping me

regards Markus

kingguppy
Posts: 37
Joined: Mon Apr 07, 2003 9:52 pm
Location: Wuppertal, Germany

Post by kingguppy » Thu Nov 20, 2003 2:09 pm


Locked