private JFreeChart createChart() {
// create the chart...
final JFreeChart chart = ChartFactory.createBarChart(model
.getDescricao(), // chart // title null, // domain axis label null, // range axis label createDataset(new Double(model.getAcumAnoAnterior()),
new Double(model.getAcumAno()), realAnoSeries, model
.getCollRealAno()), // data
PlotOrientation.VERTICAL, true, // include legend true, false);
double low;
double up;
if (model.getMax() == null && model.getMin() == null) {
maxMin();
low = model.getMin().doubleValue();
low = low - low * 5 / 100;
up = model.getMax().doubleValue();
up = up + up * 1 / 100;
}else if (model.getMax() == null){
low = model.getMin().doubleValue();
maxMin();
up = model.getMax().doubleValue();
up = up + up * 1 / 100;
}else if (model.getMin() == null){
up = model.getMax().doubleValue();
maxMin();
low = model.getMin().doubleValue();
low = low - low * 5 / 100;
}else {
up = model.getMax().doubleValue();
low = model.getMin().doubleValue();
}
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// set the background color for the chart... chart.setBackgroundPaint(new Color(231, 245, 253));
// chart.getLegend().setAnchor(Legend.SOUTH);
// get a reference to the plot for further customisation...
final CategoryPlot plot = chart.getCategoryPlot();
plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
CustomBarRenderer3D renderer = new CustomBarRenderer3D();
renderer.setLow(low);
renderer.setRealLabel(isRealLabel());
plot.setRenderer(renderer);
renderer.setPaint(Color.yellow);
plot.getRangeAxis().setUpperBound(up);
plot.getRangeAxis().setLowerBound(low);
if (isMetaLinha())
// Definindo linha meta
definirLinha(createDataset(null, null, metaSeries, model
.getCollMetaAno()), plot, low, up, 1, Color.black,
isMetaLabel());
if (isAcumLinha()) {
// Definindo linha acumulado ano JA ESTAVA COMENTADO
definirLinha(createDataset(null, null, acumuladoNoAnoSerie, model
.getCollAcumuladoAno()), plot, low, up, 2, new Color(0,
185, 0), isAcumLabel());
}
if (isMesses12Linha())
// Definindo linha acumulado ultimos 12 messes JA ESTAVA COMENTADO
definirLinha(createDataset(null, null, acumulado12MessesSeries,
model.getCollAcumulado12Messes()), plot, low, up, 3,
Color.blue, isMesses12Label());
plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
// OPTIONAL CUSTOMISATION COMPLETED. JA ESTAVA COMENTADO
return chart;
}
private void definirLinha(CategoryDataset dataset, CategoryPlot plot,
double low, double up, int numero, Color cor, boolean label) {
ValueAxis axis = new NumberAxis3D("");
CategoryItemRenderer renderer = new LineAndShapeRenderer();
if (label) {
for (int i = 1; i < dataset.getColumnCount() - 1; i++) {
Comparable coluna = dataset.getColumnKey(i);
double value = dataset.getValue(0, i).doubleValue();
CategoryTextAnnotation a = new CategoryTextAnnotation(""
+ value, coluna, value + value * 1 / 1000);
a.setCategoryAnchor(CategoryAnchor.START);
a.setFont(new Font("SansSerif", Font.BOLD, 12));
a.setPaint(cor);
a.setTextAnchor(TextAnchor.BOTTOM_LEFT);
plot.addAnnotation(a);
}
}
axis.setVisible(false);
axis.setLowerBound(low);
axis.setUpperBound(up);
plot.setRangeAxis(numero, axis);
plot.setDataset(numero, dataset);
plot.mapDatasetToRangeAxis(1, 1);
renderer.setSeriesPaint(0, cor);
plot.setRenderer(numero, renderer);
}
/**
* Creates a sample dataset.
*
* @return The dataset.
*/