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
|
public class AppChart extends JFrame {
private static final long serialVersionUID = 1L;
Map<Integer, List<Categorie>> map;
private void init() {
map = new HashMap<>();
for (int i = 0; i < 25; i++) {
List<Categorie> cat1 = new ArrayList<>();
cat1.add(new Categorie("Appli 1", Math.random() * 100));
cat1.add(new Categorie("Appli 2", Math.random() * 100));
cat1.add(new Categorie("Appli 3", Math.random() * 10));
cat1.add(new Categorie("Appli 4", Math.random() * 10));
map.put(i, cat1);
}
}
private void displayChart() {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (Map.Entry<Integer, List<Categorie>> entry : map.entrySet()) {
for (Categorie categorie : entry.getValue()) {
dataset.addValue(categorie.getCPU(), categorie.getName(), entry.getKey());
}
}
final JFreeChart barChart = ChartFactory.createBarChart("Utilisation CPU", "Heure", "%", dataset,
PlotOrientation.VERTICAL, true, true, false);
final ChartPanel cPanel = new ChartPanel(barChart);
setContentPane(cPanel);
}
private class Categorie {
String name;
double CPU;
public Categorie(String name, double cpu) {
this.name = name;
this.CPU = cpu;
}
public double getCPU() {
return CPU;
};
public String getName() {
return name;
}
}
public static void main(String[] args) {
AppChart app = new AppChart();
app.init();
app.displayChart();
app.pack();
app.setVisible(true);
}
} |
Partager