01: package com.calipso.reportgenerator.userinterface;
02:
03: import javax.swing.*;
04: import java.awt.*;
05: import org.jfree.chart.JFreeChart;
06: import org.jfree.chart.ChartFactory;
07: import org.jfree.chart.ChartPanel;
08: import org.jfree.chart.renderer.category.CategoryItemRenderer;
09: 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: * Inicializa una instancia de AreaChart
25: * @param dataset Conjunto de datos necesarios para generar el chart
26: * @param tittle Titulo del chart
27: */
28: public AreaChart(CategoryDataset dataset, String tittle,
29: Color color, boolean legend, boolean toolTips,
30: Dimension size, boolean multipleAxis) {
31: super (dataset, tittle, color, legend, toolTips, size,
32: multipleAxis);
33: previewAreaChart();
34: this .setVisible(true);
35: }
36:
37: /**
38: * Crea el chart correspondiente a partir de un <code>CategoryDataset</code>,
39: * titulo, leyenda y toolTips
40: */
41: private void previewAreaChart() {
42: JFreeChart chart = ChartFactory.createAreaChart(tittle, // chart title
43: LanguageTraslator.traslate("336"), // domain axis label
44: LanguageTraslator.traslate("337"), // range axis label
45: dataset, // data
46: org.jfree.chart.plot.PlotOrientation.VERTICAL, legend, // include legend
47: toolTips, // tooltips
48: false // urls
49: );
50:
51: // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
52:
53: // set the background color for the chart...
54: // StandardLegend legend = (StandardLegend) chart.getLegend();
55: // legend.setAnchor(StandardLegend.EAST);
56:
57: chart.setBackgroundPaint(color);
58:
59: CategoryPlot plot = chart.getCategoryPlot();
60: plot.setForegroundAlpha(0.5f);
61: //plot.setValueLabelsVisible(true);
62: plot.setDomainGridlinesVisible(true);
63: plot.setRangeGridlinesVisible(true);
64:
65: CategoryItemRenderer categoryItemRenderer = plot.getRenderer();
66: categoryItemRenderer.setItemLabelsVisible(true);
67:
68: CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
69: CategoryLabelPosition position = new CategoryLabelPosition(
70: RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
71: TextAnchor.TOP_RIGHT, -70,
72: CategoryLabelWidthType.RANGE, 70);
73: domainAxis
74: .setCategoryLabelPositions(new CategoryLabelPositions(
75: position, position, position, position));
76:
77: //domainAxis.setVerticalCategoryLabels(true);
78: domainAxis.setLowerMargin(0.0);
79: domainAxis.setUpperMargin(0.0);
80:
81: NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
82: rangeAxis.setStandardTickUnits(NumberAxis
83: .createIntegerTickUnits());
84: // OPTIONAL CUSTOMISATION COMPLETED
85:
86: // add the chart to a panel...
87: ChartPanel chartPanel = new ChartPanel(chart);
88: chartPanel.setPreferredSize(getSize());
89: add(chartPanel);
90: }
91: }
|