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
|
import java.awt.Color;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.LogarithmicAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class TestJFreeChart {
public static void main(String[] args) {
createFrame();
}
private static void createFrame(){
JFrame fenetre = new JFrame();
// creation fenetre pour les tests
fenetre.setTitle("fenêtre de tests");
fenetre.setSize(700, 800);
fenetre.setLocationRelativeTo(null);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// fin creation fenetre de test
// defini le Plot
XYPlot xyPlot = new XYPlot();
final PlotOrientation orientation = PlotOrientation.VERTICAL;
final LogarithmicAxis speedAxis = new LogarithmicAxis(null);
final LogarithmicAxis powerAxis = new LogarithmicAxis(null);
speedAxis.setAutoRange(true);
powerAxis.setAutoRange(true);
speedAxis.setAutoRangeIncludesZero(false);
powerAxis.setAutoRangeIncludesZero(false);
xyPlot.setDomainAxis(speedAxis);
xyPlot.setDomainPannable(true);
xyPlot.setRangeAxis(powerAxis);
xyPlot.setRangePannable(true);
xyPlot.setOrientation(orientation);
final XYLineAndShapeRenderer r = new XYLineAndShapeRenderer(true, false);
r.setSeriesShapesVisible(0, true);
r.setSeriesLinesVisible(0, true);
r.setSeriesPaint(0, Color.BLACK);
xyPlot.setRenderer(r);
// creation des courbes
final XYSeriesCollection xyDataset = new XYSeriesCollection();
XYSeries series = new XYSeries("test", false);
series.add(15000, 9);
series.add(37000, 60);
series.add(43000, 60);
series.add(43000, 35);
series.add(15000, 5.8);
xyDataset.addSeries(series);
xyPlot.setDataset(xyDataset);
JFreeChart chart = new JFreeChart("Title", JFreeChart.DEFAULT_TITLE_FONT, xyPlot, false);
ChartPanel chartPnl = new ChartPanel(chart) {
private static final long serialVersionUID = 1L;
@Override
public void createChartPrintJob() {
}
};
fenetre.setContentPane(chartPnl);
fenetre.setVisible(true);
}
} |
Partager