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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
package marouene;
import java.awt.Color;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
//import org.jfree.data.time.Hour;
//import org.jfree.data.time.Minute;
import org.jfree.data.time.Minute;
//import org.jfree.data.time.RegularTimePeriod;
import org.jfree.data.time.Hour;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import com.sun.org.apache.xpath.internal.operations.Minus;
/**
* An example of a time series chart using hourly data and including a null value. The plot
* has an image set for the background, and a blue range marker is added to the plot.
*
*/
public class TimeSeriesDemoTest extends ApplicationFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* A demonstration application showing a quarterly time series containing a null value.
*
* @param title the frame title.
* @throws SQLException
*/
public TimeSeriesDemoTest(final String title) throws SQLException {
super(title);
String url = "jdbc:mysql://localhost:3306/newdata";
String username = "root";
String password = "root" ;
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e){
System.out.println("Pilote non retrouvé");
}
Statement stmt = null;
try {
Connection con = DriverManager.getConnection(url,username,password);
stmt = con.createStatement();
}
catch (SQLException sqle){System.out.println("Erreur de requete");}
ResultSet rs = (ResultSet) stmt.executeQuery("select heure,ftp from affichage order by ID Desc limit 8;");
final TimeSeries series = new TimeSeries("Minute", Minute.class);
while(rs.next()){
Timestamp v1 = rs.getTimestamp("heure");
double v2=rs.getDouble("ftp");
series.addOrUpdate( new Minute(v1), v2);
}
rs.close();
final TimeSeriesCollection dataset = new TimeSeriesCollection(series);
// create a title with Unicode characters (currency symbols in this case)...
final String chartTitle = "Evolution du transfert Ftp";
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
chartTitle,
"Time",
"Débit en Ko/s",
dataset,
true,
true,
false
);
final XYPlot plot = chart.getXYPlot();
// plot.setInsets(new Insets(0, 0, 0, 20));
final Marker marker = new ValueMarker(700.0);
marker.setPaint(Color.blue);
marker.setAlpha(0.8f);
plot.addRangeMarker(marker);
plot.setBackgroundPaint(null);
final XYItemRenderer renderer = plot.getRenderer();
if (renderer instanceof StandardXYItemRenderer) {
final StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
//r.setPlotShapes(true);
r.setShapesFilled(true);
}
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(700, 400));
chartPanel.setMouseZoomable(true, false);
setContentPane(chartPanel);
}
// ****************************************************************************
// * JFREECHART DEVELOPER GUIDE *
// * The JFreeChart Developer Guide, written by David Gilbert, is available *
// * to purchase from Object Refinery Limited: *
// * *
// * <a href="http://www.object-refinery.com/jfreechart/guide.html" target="_blank">http://www.object-refinery.com/jfreechart/guide.html</a> *
// * *
// * Sales are used to provide funding for the JFreeChart project - please *
// * support us so that we can continue developing free software. *
// ****************************************************************************
/**
* Starting point for the demonstration application.
*
* @param args ignored.
* @throws SQLException
*/
public static void main(final String[] args) throws SQLException {
final TimeSeriesDemoTest demo = new TimeSeriesDemoTest("Ftp ");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
} |
Partager