Results 1 to 2 of 2
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post How to add a second series in jfreechart

    Hi people,
    Am using jfreechart to plot values that i that i read from a jtable.With the first series, my program is working ok but when i try to add a second series i get an error.
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String

    Anyone with an idea why am getting this kind of an error?
    Below is a copy of the method that am using


    Java Code:
    public void plotGraph() {
        
    final XYSeries series1 = new XYSeries("Poisoning");
    final XYSeries series2 = new XYSeries("Concentration");
    int i,num,num2;
    double axis;
    double values;
    
    //Poisoning Profile 
    num = Xenon.getRowCount();        
    
    for (i = 0; i < num; i++){
        String time;
        time = (String) Xenon.getValueAt(i, 0); 
        if (time == null)
        {
        break;
        } 
        axis = Double.parseDouble(time);
        String tmp = (String) Xenon.getValueAt(i, 1);
        values =Double.parseDouble(tmp);
    
       series1.add(axis,values);
    }
    
    //Concentration profile
    num2 = Temp.getRowCount();
    for (int k = 0; k<num2; k++) {
    String time2 = (String)Temp.getValueAt(k, 0);
    if (time2 == null){
        break;
    }
    double axis2 = Double.parseDouble(time2);
    String concentration = (String)Temp.getValueAt(k,3);
    double xen =Double.parseDouble(concentration);
    
       series2.add(axis2, xen);
      // series2.add(15, 0.5);
      // series2.add(25, 0.6);
      // series2.add(40, 0.8);
    }
    final XYSeriesCollection dataset = new XYSeriesCollection();
    
    dataset.addSeries(series1);
    dataset.addSeries(series2);
    //final XYSeriesCollection dataset1 = new XYSeriesCollection(series2);
    //JFreeChart chart = null;
    
    chart  = ChartFactory.createXYLineChart("Xenon Concentration and Poisoning",
            "Time(Hrs)", "Xenon",(XYSeriesCollection) dataset, PlotOrientation.VERTICAL, true, true, false);
    
    ChartPanel frame = new ChartPanel(chart);
    
           GraphPanel.add(frame,BorderLayout.CENTER);
           GraphPanel.validate();
     }
    your help will be highly appreciated
    thanks

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    not related to jFreeChart

    Java Code:
     String tmp = (String) Xenon.getValueAt(i, 1);
    use Double.toString() instead of (String)

Similar Threads

  1. Replies: 2
    Last Post: 02-17-2009, 04:20 PM
  2. JFreeChart 1.0.8
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-27-2007, 09:27 PM
  3. JFreeChart 1.0.7
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-17-2007, 03:13 PM
  4. JFreeChart 1.0.5
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-10-2007, 06:36 PM
  5. No Fluff Just Stuff Software Symposium Series 2007,
    By orchid in forum Reviews / Advertising
    Replies: 0
    Last Post: 04-08-2007, 09:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •