Advertisement

02.28.2008 at 01:21PM PST, ID: 23201969 | Points: 500
[x]
Attachment Details

how can i display a graph created by using a java program into a web page

Asked by raju_m8148 in WebApplications

Tags:

how can i display a graph created by using a java program into a web page.
iam getting a graph as output in a applet.
how can i display that result in webpageStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
package com.example;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.*;
 
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Hour;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
 
/**
 * A demo showing a time series with per minute data.
 *
 */
public class ServerTimeSeries extends ApplicationFrame {
 
    /**
     * A demonstration application.
     *
     * @param title  the frame title.
     */
	
    public ServerTimeSeries(final String title) {
 
        super(title);
        int i=0;
        int x[]=null;
        String url_sql = "jdbc:mysql://cib-testems02.nc.wachovia.net:3306/EMS";
	 	String userid_sql = "ems";
	 	String pwd_sql = "emspw";
	 	Connection conn_sql=null;
	 	ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("Load mysql driver");
            }
            catch(Exception e)
            {
            System.out.println("The error in loading "+e);
            }
            try{
                System.out.println("When trying to connect sql");
                conn_sql= DriverManager.getConnection( url_sql, userid_sql, pwd_sql );
                System.out.println("After connection sql");
                Statement stmt = conn_sql.createStatement( );
                String query="select OutboundMessageCount,InboundMessageCount,ts from server_fract_usage where ServerName='cib-fanout1' and ts > DATE_ADD(current_timestamp, INTERVAL -1 Day)"; //dateadd(minute,-10,getdate())";
            	rs = stmt.executeQuery(query);
            	/*for(i=1;i<12;i++){
            		System.out.println(rs.getInt(1));
            		x[i]=rs.getInt(1);}
            		;*/
            		
                final TimeSeries series = new TimeSeries("Per Minute Data", Minute.class);
                final Hour hour = new Hour();
                int z=0;
                while(rs.next()) 
                	{
                	System.out.print(rs.getLong(1));
                	System.out.print("\t");
                	System.out.print(rs.getTimestamp(3));
                	System.out.print("\n");
                	z=z+5;
                	System.out.println(rs.getLong(1));
                	series.add(new Minute(z, hour), rs.getLong(1));
                	/*for(int t=5;t<60;t=t+5)
                    {
                		
                	series.addOrUpdate(new Minute(t, hour), x[i]);
                	//series.add(rs.getTimestamp(3), rs.getInt(1));
                		
                	System.out.print(rs.getLong(1));
                	System.out.print("\t");
                	System.out.print(rs.getTimestamp(3));
                	System.out.print("\n");
                	}*/
                 }
                final TimeSeriesCollection dataset = new TimeSeriesCollection(series);
                final JFreeChart chart = ChartFactory.createTimeSeriesChart(
                    "Time Series Demo 10",
                    "Time", 
                    "OutboundMessages",
                    dataset,
                    true,
                    true,
                    false
                );
                final ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
                setContentPane(chartPanel);
                System.out.println("After Execute Query");
                }
              catch (Exception e)
                {
                System.out.println("The error in connection "+e);}
                } 
       
    public static void main(final String[] args) {
        final ServerTimeSeries demo = new ServerTimeSeries("Time Series Demo 10");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    }
}
 
 
Loading Advertisement...
 
[+][-]02.28.2008 at 02:16PM PST, ID: 21008791

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628