Je débute avec les graphiques sur java et j'ai un souci avec les histogrammes. Avec une série tout fonctionne correctement, mais lorsque j'ajoute la seconde série, elle apparaît derrière la première:
package graphiques;
import java.util.Random;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class Proba extends ApplicationFrame{
public static int nbexperiences = 2000;
public static int N = 4;
public static int nbbarres = 5;
public Proba( String applicationTitle , String chartTitle ) {
super( applicationTitle );
JFreeChart barChart = ChartFactory.createBarChart(
chartTitle,
"Score",
"Frequence",
createDataset(),
PlotOrientation.VERTICAL,
true, true, false);
ChartPanel chartPanel = new ChartPanel( barChart );
chartPanel.setPreferredSize(new java.awt.Dimension( 2000 , 367 ) );
setContentPane( chartPanel );
}
private CategoryDataset createDataset( ) {
final String f1_2 = "p=1/2";
final String f1_3 = "p=1/3";
final String tabbarres[] = new String[nbbarres];
for (int i=0;i<nbbarres;i++) {
int min;
if (i==0) {
min = 0;
} else {
min = N*i/nbbarres + 1;
}
int max = N*(i+1)/nbbarres;
tabbarres[i] = min + " a " + max;
}
final DefaultCategoryDataset dataset = new DefaultCategoryDataset( );
//Binomiale, probas 1/2 et 1/3
Random r = new Random();
int tabcount[] = new int[nbbarres];
for (int i=0;i<nbbarres;i++) {
tabcount[i] = 0;
}
for (int n=0;n<nbexperiences;n++) {
int count =0;
for (int j=0;j<N;j++) {
int ra = r.nextInt(2);
if (ra ==1) {
count ++;
}
}
int groupescore = 1;
while (count > N*(groupescore)/nbbarres) {
groupescore ++;
}
tabcount[groupescore-1]++;
}
for (int i=0;i<nbbarres;i++) {
dataset.addValue( tabcount[i] , f1_2 , tabbarres[i] );
}
tabcount = new int[nbbarres];
for (int i=0;i<nbbarres;i++) {
tabcount[i] = 0;
}
for (int n=0;n<nbexperiences;n++) {
int count =0;
for (int j=0;j<N;j++) {
int ra = r.nextInt(3);
if (ra ==2) {
count ++;
}
}
int groupescore = 1;
while (count > N*(groupescore)/nbbarres) {
groupescore ++;
}
tabcount[groupescore-1]++;
}
for (int i=0;i<nbbarres;i++) {
dataset.addValue( tabcount[i] , f1_3, tabbarres[i] );
}
return dataset;
}
public static void main( String[ ] args ) {
Proba chart = new Proba("Statistiques",
"Probas score");
chart.pack( );
RefineryUtilities.centerFrameOnScreen( chart );
chart.setVisible( true );
}
}
Histogramme avec 2 séries
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.