KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

29     public AreaChart(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         previewAreaChart();
32         this.setVisible(true);
33     }
34
35     /**
36      * Crea el chart correspondiente a partir de un <code>CategoryDataset</code>,
37      * titulo, leyenda y toolTips
38      */

39     private void previewAreaChart(){
40         JFreeChart chart = ChartFactory.createAreaChart(tittle, // chart title
41
LanguageTraslator.traslate("336"), // domain axis label
42
LanguageTraslator.traslate("337"), // range axis label
43
dataset, // data
44
org.jfree.chart.plot.PlotOrientation.VERTICAL,
45                                                         legend, // include legend
46
toolTips, // tooltips
47
false // urls
48
);
49
50         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
51

52         // set the background color for the chart...
53
// StandardLegend legend = (StandardLegend) chart.getLegend();
54
// legend.setAnchor(StandardLegend.EAST);
55

56         chart.setBackgroundPaint(color);
57
58         CategoryPlot plot = chart.getCategoryPlot();
59         plot.setForegroundAlpha(0.5f);
60         //plot.setValueLabelsVisible(true);
61
plot.setDomainGridlinesVisible(true);
62         plot.setRangeGridlinesVisible(true);
63
64         CategoryItemRenderer categoryItemRenderer = plot.getRenderer();
65         categoryItemRenderer.setItemLabelsVisible(true);
66       
67         CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
68         CategoryLabelPosition position = new CategoryLabelPosition(
69           RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT,-70, CategoryLabelWidthType.RANGE,70);
70         domainAxis.setCategoryLabelPositions(new CategoryLabelPositions(position,position,position,position));
71
72         //domainAxis.setVerticalCategoryLabels(true);
73
domainAxis.setLowerMargin(0.0);
74         domainAxis.setUpperMargin(0.0);
75
76         NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
77         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
78         // OPTIONAL CUSTOMISATION COMPLETED
79

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