HTML and JFreeChart Applet

A free public discussion forum for the JFreeChart class library.

HTML and JFreeChart Applet

Postby nabeelanwer » Thu Jun 04, 2009 10:22 am

How to form its HTML page??? from where i can find "jfreechart-1.0.0-pre2-applet-demo.jar" file??


import org.jfree.chart.demo.*;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.lang.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.demo.Time;
import java.text.*;
import java.util.StringTokenizer;
import javax.swing.JApplet;
import java.awt.*;

/**
* A simple demonstration application showing how to create a line chart using data from a
* {@link CategoryDataset}.
*/
public class STATSGRAPH extends JApplet{

public void init() {

final CategoryDataset dataset = createDataset() ;
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
//setContentPane(chartPanel);

chartPanel.setPopupMenu(null);
//add the chartPanel to the container (getContentPane is inherited from JApplet which AppletGraph extends).
Container content = getContentPane();
content.add(chartPanel);

//JFreeChart jFreeChart = generateGraph();

//Put the jFreeChart in a chartPanel
//ChartPanel chartPanel = new ChartPanel(jFreeChart);
//chartPanel.setPreferredSize(new Dimension(900,600));

}//end of init method




/**
* Creates a new demo.
*
* @param title the frame title.
*/
/*public STATSGRAPH() {
super("XIPX Stats");
final CategoryDataset dataset = createDataset() ;
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(1000, 500));
setContentPane(chartPanel);
}
*/






/**
* Creates a sample dataset.
*
* @return The dataset.
*/
private CategoryDataset createDataset() {

// row keys...
final String series1 = "First";
final String series2 = "Second";
final String series3 = "Third";

// column keys...
final String type1 = "1";
final String type2 = "2";
final String type3 = "3";
final String type4 = "4";
final String type5 = "5";
final String type6 = "6";
final String type7 = "7";
final String type8 = "8";
final String type9 = "9";




// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DB_Name",
"user_name", "password");

Statement stmt = con.createStatement();
ResultSet rslt = stmt.executeQuery("SELECT FROM_UNIXTIME(ENDTIME), SUM(BILLDURATION) FROM XCORE.STATISTICS S WHERE PREFIX=8801 AND BEGINTIME>=1242795600 AND ENDTIME<1242881999 AND GROUPID=396 GROUP BY ENDTIME ORDER BY ENDTIME");

Time time = new Time();
System.currentTimeMillis();

Date date= new Date();

date = time.getLocalDateTime((System.currentTimeMillis())*1000);
//date.setMinutes(5);


int count=0;
while(rslt.next()){
//y-axis //x-axis
//dataset.addValue(rslt.getInt("BILLDURATION"), series1, String.valueOf(count));

String strSearchFromHour=rslt.getString("FROM_UNIXTIME(ENDTIME)");
StringTokenizer strTokenFromTime = new StringTokenizer(strSearchFromHour," ");


String DateFrom="";
String TimeFrom="";
String HR="";

if (strTokenFromTime.hasMoreTokens()) {

DateFrom = strTokenFromTime.nextToken();

if (strTokenFromTime.hasMoreTokens()) {
TimeFrom = strTokenFromTime.nextToken();
StringTokenizer strTokenFromHour = new StringTokenizer(TimeFrom,":");
if(strTokenFromHour.hasMoreTokens()){
HR=strTokenFromHour.nextToken();
}
} //end of second if

}//end of first if
dataset.addValue(rslt.getInt(2), series1, HR);
System.out.println(DateFrom);
System.out.println(TimeFrom);
System.out.println(HR);
// to check the values ...
//System.out.println(rslt.getInt("PREFIX"));
count++;
}

rslt.close();
if(!con.isClosed())
System.out.println("Successfully connected to " + "MySQL server using TCP/IP...");

} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}


return dataset;

}

/**
* Creates a sample chart.
*
* @param dataset a dataset.
*
* @return The chart.
*/
private JFreeChart createChart(final CategoryDataset dataset) {

// create the chart...
final JFreeChart chart = ChartFactory.createLineChart(
"Xipx Statistics Graph", // chart title
"Hours", // domain axis label
"BillDuration", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);

// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// final StandardLegend legend = (StandardLegend) chart.getLegend();
// legend.setDisplaySeriesShapes(true);
// legend.setShapeScaleX(1.5);
// legend.setShapeScaleY(1.5);
//legend.setDisplaySeriesLines(true);

chart.setBackgroundPaint(Color.white);

final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);

// customise the range axis...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);



// customise the renderer...
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
// renderer.setDrawShapes(true);

renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,1.0f, new float[] {10.0f, 6.0f}, 0.0f));
renderer.setSeriesStroke(
1, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {6.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
2, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {2.0f, 6.0f}, 0.0f
)
);
// OPTIONAL CUSTOMISATION COMPLETED.

return chart;
}

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
/* public static void main(final String[] args) {

final STATSGRAPH demo = new STATSGRAPH();
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}
*/
}
nabeelanwer
 
Posts: 1
Joined: Thu Jun 04, 2009 10:13 am

Return to JFreeChart - General

Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], Google [Bot], Yahoo [Bot] and 13 guests