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
|
package chart;
import java.awt.Dimension;
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.axis.NumberTickUnit;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.CategoryTableXYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class ScatterPlotDemo extends ApplicationFrame {
private static final long serialVersionUID = 1L;
public ScatterPlotDemo(String title) {
super(title);
CategoryTableXYDataset dataset = new CategoryTableXYDataset();
dataset.add(2, 4, "a");
dataset.add(11, 2, "b");
JFreeChart chart = ChartFactory.createScatterPlot("titre", "x", "y", dataset, PlotOrientation.VERTICAL, true, true, false);
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
XYPlot plot = chart.getXYPlot();
NumberAxis xAxe = (NumberAxis) plot.getDomainAxis();
xAxe.setLabel("xXx");
xAxe.setTickUnit(new NumberTickUnit(1));
NumberAxis yAxe = (NumberAxis) plot.getRangeAxis();
yAxe.setLabel("yYy");
yAxe.setTickUnit(new NumberTickUnit(1));
}
public static void main(String[] args) {
ScatterPlotDemo demo = new ScatterPlotDemo("fenêtre");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
} |
Partager