KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > HorizontalBarChart


1 package com.calipso.reportgenerator.userinterface;
2
3
4 import org.jfree.chart.ChartFactory;
5 import org.jfree.chart.JFreeChart;
6 import org.jfree.chart.ChartPanel;
7 import org.jfree.chart.axis.NumberAxis;
8 import org.jfree.chart.plot.CategoryPlot;
9 import org.jfree.data.category.CategoryDataset;
10
11 import java.awt.*;
12
13 import javax.swing.*;
14
15 import com.calipso.reportgenerator.common.LanguageTraslator;
16
17 /**
18  * Representa un chart de tipo Barras Horizontales
19  */

20
21 public class HorizontalBarChart extends Charts{
22
23
24   /**
25    * Inicializa una instancia de HorizontalBarChart
26    * @param dataset Conjunto de datos necesarios para generar el chart
27    * @param tittle Titulo de el chart
28    */

29     public HorizontalBarChart(CategoryDataset dataset, String JavaDoc tittle, Color color, boolean legend, boolean toolTips, Dimension size, boolean multipleAxis) {
30         super(dataset, tittle, color, legend, toolTips, size, multipleAxis);
31         previewHorizontalBarChart();
32         this.setVisible(true);
33     }
34
35     /**
36      * Inicializa un conjunto de datos con las respectivas descripciones
37      * y crea el chart correspondiente
38      */

39     private void previewHorizontalBarChart() {
40
41
42
43     JFreeChart chart = ChartFactory.createBarChart(
44                                                     tittle, // chart title
45
LanguageTraslator.traslate("337"), // range axis label
46
LanguageTraslator.traslate("336"), // range axis label
47
dataset, // data
48
org.jfree.chart.plot.PlotOrientation.HORIZONTAL,
49                                                     legend, // include legend
50
toolTips,
51                                                     false
52                                                 );
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         // change the auto tick unit selection to integer units only...
63
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
64         rangeAxis.setAutoRangeIncludesZero(true);
65         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
66
67         ChartPanel chartPanel = new ChartPanel(chart);
68       chartPanel.setPreferredSize(getSize());
69         add(chartPanel);
70
71     }
72
73 }
74
75
Popular Tags