Duvida simples. Eu crio um relatório com o JasperReport, que tem um gráfico de barras do JFreeChart. O gráfico mostra a média dos meses de 2007 ,de 2008 e a meta. Em alguns relatórios aparece na ordem correta: 2007, 2008 e meta. Mas a maioria das vezes aparace na ordem errada. 2008, 2007, meta. Pensei que fosse a ordem que os parâmetros são adicionados, mas não resolveu. Alguém tem alguma sugestão??
A seguir os métodos utilizados:
private void adicionarGraficoDeBarras(RelatorioInidcadoresDTO relatorio) {
AvaliacaoDTO avaliacaoDTO = (AvaliacaoDTO) relatorio.getAvaliacaoPeriodoFinal();
Map data = new HashMap();
data.put(relatorio.getAnoAnterior(), relatorio.getMediaAnoAnterior());
data.put(relatorio.getAno(), relatorio.getMediaAno());
Double meta = null;
if(avaliacaoDTO.getMeta() != null){
meta = new Double(avaliacaoDTO.getMeta().doubleValue());
}
data.put(" Meta",meta);
relatorio.setBarChart( createBarChart( "Resultado do Período", null, null, data, 260, 154 ) );
}
private BufferedImage createBarChart(String title, String xAxisLabel, String yAxisLabel, Map data, int width, int heigth) {
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
String rowKey = "Employee";//??
for (Iterator it = data.entrySet().iterator(); it.hasNext();) {
Entry entry = (Entry) it.next();
String key = (String) entry.getKey();
Double value = (Double) entry.getValue();
defaultCategoryDataset.addValue( value, rowKey, key);
}
JFreeChart chart = ChartFactory.createBarChart
(title,
xAxisLabel,
yAxisLabel,
(CategoryDataset) defaultCategoryDataset,
PlotOrientation.VERTICAL,
false,
false,
false
);
CategoryPlot plot = chart.getCategoryPlot();
CustomRenderer barRenderer = new CustomRenderer(
new Paint[]
{
new Color(193,157,246),
new Color(152,185,185),
new Color(72,72,117),
new Color(157,141,110),
new Color(181,181,119),
new Color(151,199,151),
new Color(191,167,182),
new Color(217,182,144),
new Color(102,153,255),
new Color(0,102,102),
new Color(84,72,84),
new Color(180,236,203),
}
);
barRenderer.setItemLabelsVisible(true);
plot.setRenderer(barRenderer);
barRenderer.setDrawBarOutline(false);
chart.getTitle().setFont(new java.awt.Font("Arial",Font.BOLD,12));
return chart.createBufferedImage(width, heigth);
}