puntito
Programmer
- Mar 22, 2006
- 18
I have been working with this library and want to share mi code.
Hope this could help somebody.
More Info at:
Code:
private static JFreeChart doingChart(String weekIni, String weekFinal, Integer aplication) {
JFreeChart chart = null;
GraficasDAO dao1 = new GraficasDAO();
ArrayList results = new ArrayList();
dataset = new DefaultCategoryDataset();
//Asking 4 data information
results = (ArrayList)dao1.totXEquipo(doingMapa(weekIni, weekFinal,aplication));
//Filling dataset with the results
datosTotXsem(results,-1);
//creating chart.
// Chart name, X axis label, Y axis value, data set
chart = ChartFactory.createBarChart("Sells by PhoneType", "PERIOD", "QUANTITY",dataset, PlotOrientation.VERTICAL, true, true, true);
//get a reference to the plot for further customisation...
CategoryPlot plot = chart.getCategoryPlot();
plot.setDomainGridlinePaint(Color.WHITE);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.GRAY);
chart.setBackgroundPaint(new Color(255,255,255));
//How to show the values
DecimalFormat decimalformat1 = new DecimalFormat("##,###");
CategoryItemRenderer renderer = new BarRenderer();
//Changing color to the bars
renderer.setSeriesPaint(0,new Color(0,204,204));
renderer.setSeriesPaint(2,new Color(153,204,255));
renderer.setSeriesPaint(3,new Color(255,102,0));
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
renderer.setBaseItemLabelsVisible(true);
chart.getCategoryPlot().setRenderer(renderer);
return chart;
}
public static void datosTotXsem(ArrayList lista, int week){
//obtaining each result
for(int i=0; i < lista.size(); i++ ) {
DataSetVO vo = (DataSetVO) lista.get(i);
String title= "Week"+week;
//data could be a float value or int
if (vo.isFlag()){
dataset.setValue(vo.getYaxisF(),vo.getXAxis(),vo.getSerie()+week);
dataFound = true;
}else{
dataset.setValue(vo.getYAxis(),vo.getXAxis(),title);
dataFound = true;
}
}
}
Hope this could help somebody.
More Info at: