KickJava   Java API By Example, From Geeks To Geeks.

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


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

22
23 public class VerticalBarChart extends Charts{
24
25
26   /**
27    * Crea una instancia de VerticalBarChart.
28    * @param dataset
29    * @param tittle
30    * @param color
31    * @param legend
32    * @param toolTips
33    */

34     public VerticalBarChart(CategoryDataset dataset, String JavaDoc tittle, Color color, boolean legend, boolean toolTips, Dimension size, boolean multipleAxis) {
35         super(dataset, tittle, color, legend, toolTips, size, multipleAxis);
36         previewVerticalhart();
37         this.setVisible(true);
38     }
39
40     /**
41      * Crea el chart correspondiente a partir de un <code>CategoryDataset</code>,
42      * titulo, leyenda y toolTips
43      */

44     void previewVerticalhart(){
45         // create the chart...
46
JFreeChart chart = ChartFactory.createBarChart(
47                                                      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,
52                                                      legend, // include legend
53
toolTips,
54                                                      false
55                                                  );
56
57         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
58

59         // set the background color for the chart...
60
chart.setBackgroundPaint(color);
61
62         // get a reference to the plot for further customisation...
63
CategoryPlot plot = chart.getCategoryPlot();
64
65         // skip some labels if they overlap...
66
CategoryAxis domainAxis = plot.getDomainAxis();
67         CategoryLabelPosition position = new CategoryLabelPosition(
68             RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT,-70, CategoryLabelWidthType.RANGE,70);
69         domainAxis.setCategoryLabelPositions(new CategoryLabelPositions(position,position,position,position));
70
71         // set the range axis to display integers only...
72
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
73         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
74
75         // OPTIONAL CUSTOMISATION COMPLETED.
76

77         // add the chart to a panel...
78
ChartPanel chartPanel = new ChartPanel(chart);
79         chartPanel.setPreferredSize(getSize());
80         add(chartPanel);
81
82     }
83 }
84
85
Popular Tags