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
|
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
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.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class Dessin {
private CategoryPlot plot= new CategoryPlot();
private int secondaryDatasetIndex = 0;
private static double[] a= new double[9];
private JPanel p;
public Dessin(final double[] a) {
final CategoryDataset dataset1 = createRandomDataset("");
final JFreeChart chart = ChartFactory.createLineChart( "", "", "",dataset1, PlotOrientation.HORIZONTAL, false, true, false);
chart.setBackgroundPaint(Color.white);
this.plot = chart.getCategoryPlot();
this.plot.setBackgroundPaint(Color.white);
this.plot.setDomainGridlinePaint(Color.orange);
this.plot.setRangeGridlinePaint(Color.orange);
this.plot.setDomainAxisLocation(0,AxisLocation.BOTTOM_OR_RIGHT);
this.plot.setRangeGridlinesVisible(true);
this.plot.setDomainGridlinesVisible(true);
LineAndShapeRenderer renderer
= (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setUseFillPaint(true);
renderer.setBaseFillPaint(Color.white);
final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis();
rangeAxis.setAutoRangeIncludesZero(false);
final JPanel content = new JPanel(new BorderLayout());
final ChartPanel chartPanel = new ChartPanel(chart);
content.add(chartPanel);
p = new JPanel(new FlowLayout());
content.add(p, BorderLayout.SOUTH);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
JFrame jFrame = new JFrame();
jFrame.setSize(805, 605);
jFrame.setTitle("Bec 96 1.0.0");
jFrame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
jFrame.setLocationRelativeTo(null);
jFrame.setContentPane(content);
jFrame.setVisible(true);
}
private CategoryDataset createRandomDataset(final String name) {
final DefaultCategoryDataset result = new DefaultCategoryDataset();
double value = 100.0;
for (int i = 0; i < 9; i++) {
final String key = "hhh"+i;
value = (a[i]);
result.addValue(value, name, key);
}
return result;
}
public static void main(final String[] args) {
for (int i=0;i<9;i++)
{
a[i]=i*2;
}
final Dessin demo = new Dessin(a);
}
} |
Partager