01: package com.calipso.reportgenerator.userinterface;
02:
03: import org.jfree.chart.JFreeChart;
04: import org.jfree.chart.ChartFactory;
05: import org.jfree.chart.ChartPanel;
06: import org.jfree.chart.axis.*;
07: import org.jfree.chart.plot.CategoryPlot;
08: import org.jfree.ui.RectangleAnchor;
09: import org.jfree.ui.TextAnchor;
10: import org.jfree.text.TextBlockAnchor;
11: import org.jfree.data.category.CategoryDataset;
12:
13: import javax.swing.*;
14: import java.awt.*;
15:
16: import com.calipso.reportgenerator.common.LanguageTraslator;
17:
18: /**
19: * Representa un grafico de tipo Barras Verticales .
20: */
21:
22: public class VerticalBarChart extends Charts {
23:
24: /**
25: * Crea una instancia de VerticalBarChart.
26: * @param dataset
27: * @param tittle
28: * @param color
29: * @param legend
30: * @param toolTips
31: */
32: public VerticalBarChart(CategoryDataset dataset, String tittle,
33: Color color, boolean legend, boolean toolTips,
34: Dimension size, boolean multipleAxis) {
35: super (dataset, tittle, color, legend, toolTips, size,
36: multipleAxis);
37: previewVerticalhart();
38: this .setVisible(true);
39: }
40:
41: /**
42: * Crea el chart correspondiente a partir de un <code>CategoryDataset</code>,
43: * titulo, leyenda y toolTips
44: */
45: void previewVerticalhart() {
46: // create the chart...
47: JFreeChart chart = ChartFactory.createBarChart(tittle, // chart title
48: LanguageTraslator.traslate("336"), // domain axis label
49: LanguageTraslator.traslate("337"), // range axis label
50: dataset, // data
51: org.jfree.chart.plot.PlotOrientation.VERTICAL, legend, // include legend
52: toolTips, false);
53:
54: // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
55:
56: // set the background color for the chart...
57: chart.setBackgroundPaint(color);
58:
59: // get a reference to the plot for further customisation...
60: CategoryPlot plot = chart.getCategoryPlot();
61:
62: // skip some labels if they overlap...
63: CategoryAxis domainAxis = plot.getDomainAxis();
64: CategoryLabelPosition position = new CategoryLabelPosition(
65: RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
66: TextAnchor.TOP_RIGHT, -70,
67: CategoryLabelWidthType.RANGE, 70);
68: domainAxis
69: .setCategoryLabelPositions(new CategoryLabelPositions(
70: position, position, position, position));
71:
72: // set the range axis to display integers only...
73: NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
74: rangeAxis.setStandardTickUnits(NumberAxis
75: .createIntegerTickUnits());
76:
77: // OPTIONAL CUSTOMISATION COMPLETED.
78:
79: // add the chart to a panel...
80: ChartPanel chartPanel = new ChartPanel(chart);
81: chartPanel.setPreferredSize(getSize());
82: add(chartPanel);
83:
84: }
85: }
|