Results 1 to 13 of 13
  1. #1
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default Plot Chart on Jpanel.

    Hello everyone! i want to create and plot my Jfreechart on Panel that placed on main form..I use this code
    Java Code:
      JFrame jfrm;
            XYPlot plot;
    
            jfrm = new JFrame();
            Toolkit tk = Toolkit.getDefaultToolkit();
            int xSize = ((int) tk.getScreenSize().getWidth());
            int ySize = ((int) tk.getScreenSize().getHeight());
            jfrm.setSize(xSize, ySize);
            jfrm.setVisible(true);
            jfrm.setResizable(true);
    
    
            XYSeries s1 = new XYSeries("IV");
            double min=1000000;
            double max=0;
    
    
      try {
         connection = DriverManager.getConnection("jdbc:mysql://localhost/mysql","root", "");
         statement = connection.createStatement();
         ResultSet rs=statement.executeQuery(createDatabaseQyery);
    
         while (rs.next()){
         
         String str =rs.getString("price");
         Float f = new Float(str);
         double x = f.doubleValue();
    
         String t=rs.getString("time");
         DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
    
                   try{
                    java.util.Date y = sdf.parse(t);
                    calendar.setTime(y);
                    String time=Integer.toString(calendar.get(Calendar.HOUR_OF_DAY))+":"+Integer.toString(calendar.get(Calendar.MINUTE))+":"+Integer.toString(calendar.get(Calendar.SECOND));
                  
                   }
                    catch (Exception e){
                 e.printStackTrace();
                 }
    
                s1.add(i,x);
    
                i=i+1;
                if (min>x) min=x;
                if (max<x) max=x;
    
         }
    
         }
         catch (Exception e)
         {
         e.printStackTrace();
         }
      finally {
    if (statement != null) {
    try {
    statement.close();
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    }
    }
    if (connection!= null) {
    try {
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }
    
    
            XYDataset xyDataset = new XYSeriesCollection(s1);
           
    
    
            JFreeChart chart = ChartFactory.createXYLineChart("IV", "", "", xyDataset,PlotOrientation.VERTICAL, false, false, false);
     
    
            final ChartPanel chartPanel = new ChartPanel(chart);
        //   jfrm.add(chartPanel);
            jPanel4.add(chartPanel);
    
           chart.getXYPlot().getRangeAxis().setLowerBound(min-2);
           chart.getXYPlot().getRangeAxis().setUpperBound(max+2);
    But i see nothing on jPanel.. But then i plot my chat on JFRM(dinamical created FRAME ) the chart appear on them..Where is a problem?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Where in your code are you adding the JPanel to a root container and displaying it? In other words, I don't see where you've added your JPanel to a JFrame.

  3. #3
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    no..I using a Netbeand. Ive created a form and drop on this from Jpanel4.

  4. #4
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Is it possible to plot a chart on a Panel that dropped on maim form?

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,449
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by cowboy View Post
    Is it possible to plot a chart on a Panel that dropped on maim form?
    What does your fine manual say about it?

    kind regards,

    Jos

  6. #6
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    tell me please or just give me a link for this

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    For me at least, it's hard to give a recommendation without knowing exactly what your problem is, and it's going to be your job to find this out. I'm not even sure, if you are asking a Netbeans question or Java question? My suggestion would be to get this working in a non-netbeans-generated very simple Swing app first. Divide and conquer in order to debug your problem.

  8. #8
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    For me at least, it's hard to give a recommendation without knowing exactly what your problem is, and it's going to be your job to find this out.
    I create project using Netbeabs IDE. May be my English language are so worst :( ?
    I ll show you a printscreen :

    This is a printscreen of my main form in neatBeans.Purple scope-it is a jPanel4. i just want to plot my chart on them and i wrote this for that
    Java Code:
    jPanel4.add(chartPanel);
    But it does not..
    And this is another printscreen


    In this case i just plot my chart on dinamically created frame
    Java Code:
    jfrm.add(chartPanel);
    Help me please
    Last edited by cowboy; 12-12-2009 at 03:44 PM.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What layout does your jPanel4 use? Have you tried setting its layout to BorderLayout and adding your chartPanel to it BorderLayout.CENTER?

  10. #10
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Can you give some example how i can done this?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I can give you plenty of examples of how to do this without NetBeans, the best is here: Laying out components within a container.

    But to do it in NetBeans, you'll likely have to right click on the JPanel, inspect its properties and set its layout property to BorderLayout. If you don't understand this, then please look at your NetBeans help files for more.

    But again, I suggest that you learn to code this without NetBeans code-generation and only use NetBeans code after you have a basic understanding of Swing coding. The tutorial linked above has all you need to learn how to code Swing.

  12. #12
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Thanks, i ll try to create some app without netbeans..

    From Russia with love, ofcose :)

  13. #13
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Thank to all but i should to add this string in my code
    jPanel4.add(chartPanel,BorderLayout.EAST);
    And set the appropiate Layout to Jpanel in Net beans..
    And to all.In Java Guide wrote that it is highly recommended to use a IDE instead codding by the hand for more convinience.

Similar Threads

  1. ECG plot in a textfile
    By samson in forum Java 2D
    Replies: 13
    Last Post: 01-28-2012, 04:02 PM
  2. Plot-applet
    By zkab in forum Java Applets
    Replies: 4
    Last Post: 10-03-2009, 03:03 PM
  3. How to plot a dot graph
    By Manfizy in forum Java 2D
    Replies: 3
    Last Post: 01-28-2009, 02:57 PM
  4. Demo bar chart and pie chart
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:22 PM
  5. Need Help for Dot Plot Graph
    By BHCluster in forum Java 2D
    Replies: 5
    Last Post: 04-15-2008, 02:54 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
  •