Results 1 to 13 of 13
Thread: Plot Chart on Jpanel.
- 12-11-2009, 06:36 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
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
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?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);
-
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.
- 12-12-2009, 05:26 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
no..I using a Netbeand. Ive created a form and drop on this from Jpanel4.
- 12-12-2009, 09:25 AM #4
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
Is it possible to plot a chart on a Panel that dropped on maim form?
- 12-12-2009, 12:16 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 12-12-2009, 02:29 PM #6
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
tell me please or just give me a link for this
-
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.
- 12-12-2009, 03:42 PM #8
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
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 thatBut it does not..Java Code:jPanel4.add(chartPanel);
And this is another printscreen

In this case i just plot my chart on dinamically created frame
Help me pleaseJava Code:jfrm.add(chartPanel);
Last edited by cowboy; 12-12-2009 at 03:44 PM.
-
What layout does your jPanel4 use? Have you tried setting its layout to BorderLayout and adding your chartPanel to it BorderLayout.CENTER?
- 12-12-2009, 03:55 PM #10
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
Can you give some example how i can done this?
-
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-2009, 07:11 PM #12
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
Thanks, i ll try to create some app without netbeans..
From Russia with love, ofcose :)
- 12-13-2009, 09:38 AM #13
Member
- Join Date
- Oct 2009
- Posts
- 48
- Rep Power
- 0
Similar Threads
-
ECG plot in a textfile
By samson in forum Java 2DReplies: 13Last Post: 01-28-2012, 04:02 PM -
Plot-applet
By zkab in forum Java AppletsReplies: 4Last Post: 10-03-2009, 03:03 PM -
How to plot a dot graph
By Manfizy in forum Java 2DReplies: 3Last Post: 01-28-2009, 02:57 PM -
Demo bar chart and pie chart
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:22 PM -
Need Help for Dot Plot Graph
By BHCluster in forum Java 2DReplies: 5Last Post: 04-15-2008, 02:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks