public BufferedImage creagrafica(Date fecha) {
Integer cont = 0;
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String row = "";
try {
List lista = new ArrayList();
lista = controlador.getDatosProduccion(fecha);
Iterator i = lista.iterator();
System.out.println("ENTRANDO EN BUCLE");
while (i.hasNext()) {
cont++;
row = "row " + cont;
Object[] registro = (Object[])i.next();
int hora = (Integer)registro[0];
int total = (Integer)registro[1];
dataset.addValue(total, row,hora);
}
} catch (Exception e) {
System.out.println("excepcion controlada en grafica de hora");
}
// TODO
////////////////////////////////////////////////////////NUEVO
//final XYSeriesCollection collection = new XYSeriesCollection();
// collection.addSeries(series);
// final IntervalXYDataset data1 = collection;
JFreeChart chart = ChartFactory.createBarChart("","","produccion",dataset,PlotOrientation.HORIZONTAL,false,false,false );
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
plot.setAnchorValue(30);
// customise the range axis...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
CategoryAxis axis = plot.getDomainAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// customise the renderer...
rangeAxis.setRange(0,10);
rangeAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 1));
axis.setLabelFont(new Font("SansSerif", Font.PLAIN, 1));
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(1));
axis.setLowerMargin(0);
axis.setMaximumCategoryLabelLines(10);
BufferedImage image = chart.createBufferedImage(110,190);
return image;
}
|