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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
package net.epimarket.services;
import java.util.ArrayList;
import java.util.Iterator;
import monPackage.models.Produits;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.util.Rotation;
public class PieChart3DDemo1 extends ApplicationFrame {
private static final long serialVersionUID = 1L;
private ArrayList<Object> resultat;
private double pots = 0;
private double eclairage = 0;
private double ventilation = 0;
private double graines = 0;
private double promo = 0;
private double total = 0;
public ArrayList<Object> getResultat() {
return resultat;
}
public void setResultat(ArrayList<Object> resultat) {
this.resultat = resultat;
}
public PieChart3DDemo1(final String title) {
super(title);
final PieDataset dataset = createSampleDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
private PieDataset createSampleDataset() {
Factory newFactory = new Factory();
resultat = new ArrayList<Object>();
newFactory.dbConnect();
this.resultat = newFactory.select("produits");
Iterator<Object> itp = resultat.iterator();
while (itp.hasNext())
{
Produits cur = (Produits)itp.next();
if ("Promotion".compareTo(cur.getRubrique()) == 0)
{
promo = promo + 1;
}
else if ("Pots".compareTo(cur.getRubrique()) == 0)
{
pots = pots + 1;
}
else if ("Eclairage".compareTo(cur.getRubrique()) == 0)
{
eclairage = eclairage + 1;
}
else if ("Ventilation".compareTo(cur.getRubrique()) == 0)
{
ventilation = ventilation + 1;
}
else if ("Graines".compareTo(cur.getRubrique()) == 0)
{
graines = graines + 1;
}
}
total = promo + pots + eclairage + ventilation + graines;
promo = promo * 100 / total;
pots = pots * 100 / total;
eclairage = eclairage * 100 / total;
ventilation = ventilation * 100 / total;
graines = graines * 100 / total;
final DefaultPieDataset result = new DefaultPieDataset();
result.setValue("Pots", new Double(pots));
result.setValue("Eclairage", new Double(eclairage));
result.setValue("Ventilation", new Double(ventilation));
result.setValue("Graines", new Double(graines));
result.setValue("Promotion", new Double(promo));
return result;
}
private JFreeChart createChart(final PieDataset dataset) {
final JFreeChart chart = ChartFactory.createPieChart3D(
"Part des produits en stock (%)",
dataset,
true,
true,
false
);
final PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.3f);
plot.setNoDataMessage("No data to display");
return chart;
}
public static void main(final String[] args) {
final PieChart3DDemo1 demo = new PieChart3DDemo1("Part des produits en stock (%)");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
} |
Partager