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
|
double[] doubetudiants = new double[]{
1,
2,
3
};
double[] doubetudiantes = new double[]{
4,
5,
6
};
String[] strannee = new String[]{
"2000",
"2001",
"2002"
};
String s = "étudiants";
String s1 = "étudiantes";
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
for(int j=0;j<3;j++){
defaultcategorydataset.addValue(doubetudiants[j],s,strannee[j]);
defaultcategorydataset.addValue(doubetudiantes[j],s1,strannee[j]);
}
JFreeChart graphe = ChartFactory.createBarChart("test", "Année", "Nbre d'inscris", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
graphe.setBackgroundPaint(ChartColor.white);
CategoryPlot categoryplot = graphe.getCategoryPlot();
categoryplot.setBackgroundPaint(ChartColor.lightGray);
categoryplot.setDomainGridlinePaint(ChartColor.white);
categoryplot.setRangeGridlinePaint(ChartColor.white);
NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setUpperMargin(0.14999999999999999D);
numberaxis.setAutoRange(false);
CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
categoryitemrenderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
try{
ChartUtilities.saveChartAsPNG(new File("chartHisto2D.png"), graphe, 500,300);
}catch(Exception e){System.out.println("plop");}; |
Partager