01: package com.calipso.reportgenerator.userinterface;
02:
03: import org.jfree.chart.ChartFactory;
04: import org.jfree.chart.JFreeChart;
05: import org.jfree.chart.ChartPanel;
06: import org.jfree.chart.axis.NumberAxis;
07: import org.jfree.chart.plot.CategoryPlot;
08: import org.jfree.data.category.CategoryDataset;
09:
10: import java.awt.*;
11:
12: import javax.swing.*;
13:
14: import com.calipso.reportgenerator.common.LanguageTraslator;
15:
16: /**
17: * Representa un chart de tipo Barras Horizontales
18: */
19:
20: public class HorizontalBarChart extends Charts {
21:
22: /**
23: * Inicializa una instancia de HorizontalBarChart
24: * @param dataset Conjunto de datos necesarios para generar el chart
25: * @param tittle Titulo de el chart
26: */
27: public HorizontalBarChart(CategoryDataset dataset, String tittle,
28: Color color, boolean legend, boolean toolTips,
29: Dimension size, boolean multipleAxis) {
30: super (dataset, tittle, color, legend, toolTips, size,
31: multipleAxis);
32: previewHorizontalBarChart();
33: this .setVisible(true);
34: }
35:
36: /**
37: * Inicializa un conjunto de datos con las respectivas descripciones
38: * y crea el chart correspondiente
39: */
40: private void previewHorizontalBarChart() {
41:
42: JFreeChart chart = ChartFactory.createBarChart(
43: tittle, // chart title
44: LanguageTraslator.traslate("337"), // range axis label
45: LanguageTraslator.traslate("336"), // range axis label
46: dataset, // data
47: org.jfree.chart.plot.PlotOrientation.HORIZONTAL,
48: legend, // include legend
49: toolTips, false);
50:
51: // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
52:
53: // set the background color for the chart...
54: chart.setBackgroundPaint(color);
55:
56: // get a reference to the plot for further customisation...
57: CategoryPlot plot = chart.getCategoryPlot();
58:
59: // change the auto tick unit selection to integer units only...
60: NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
61: rangeAxis.setAutoRangeIncludesZero(true);
62: rangeAxis.setStandardTickUnits(NumberAxis
63: .createIntegerTickUnits());
64:
65: ChartPanel chartPanel = new ChartPanel(chart);
66: chartPanel.setPreferredSize(getSize());
67: add(chartPanel);
68:
69: }
70:
71: }
|