001: package com.calipso.reportgenerator.userinterface;
002:
003: import org.jfree.chart.JFreeChart;
004: import org.jfree.chart.ChartFactory;
005: import org.jfree.chart.ChartPanel;
006: import org.jfree.chart.renderer.category.LineAndShapeRenderer;
007: import org.jfree.chart.axis.*;
008: import org.jfree.chart.plot.CategoryPlot;
009: import org.jfree.chart.plot.Marker;
010: import org.jfree.chart.plot.ValueMarker;
011: import org.jfree.ui.RectangleAnchor;
012: import org.jfree.ui.TextAnchor;
013: import org.jfree.text.TextBlockAnchor;
014: import org.jfree.data.category.CategoryDataset;
015:
016: import java.awt.*;
017:
018: import com.calipso.reportgenerator.common.LanguageTraslator;
019:
020: /**
021: * Representa un grafico de Lineas
022: */
023:
024: public class LineChart extends Charts {
025:
026: /**
027: * Inicializa una instancia de LineChart
028: * @param dataset
029: * @param tittle
030: * @param color
031: * @param legend
032: * @param toolTips
033: */
034: public LineChart(CategoryDataset dataset, String tittle,
035: Color color, boolean legend, boolean toolTips,
036: Dimension size, boolean multipleAxis) {
037: super (dataset, tittle, color, legend, toolTips, size,
038: multipleAxis);
039: previewLineChart();
040: this .setVisible(true);
041: }
042:
043: /**
044: * Crea el chart correspondiente a partir de un <code>CategoryDataset</code>,
045: * titulo, leyenda y toolTips
046: */
047: void previewLineChart() {
048:
049: // create the chart...
050: JFreeChart chart = ChartFactory.createLineChart(tittle, // chart title
051: LanguageTraslator.traslate("336"), // domain axis label
052: LanguageTraslator.traslate("337"), // range axis label
053: dataset, // data
054: org.jfree.chart.plot.PlotOrientation.VERTICAL, legend, // include legend
055: toolTips, // tooltips
056: true // urls
057: );
058:
059: // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
060:
061: chart.setBackgroundPaint(color);
062:
063: CategoryPlot plot = chart.getCategoryPlot();
064:
065: // set the stroke for each series...
066: plot.getRenderer().setSeriesStroke(
067: 0,
068: new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
069: BasicStroke.JOIN_ROUND, 1.0f, new float[] {
070: 10.0f, 6.0f }, 0.0f));
071: plot.getRenderer().setSeriesStroke(
072: 1,
073: new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
074: BasicStroke.JOIN_ROUND, 1.0f, new float[] {
075: 6.0f, 6.0f }, 0.0f));
076: plot.getRenderer().setSeriesStroke(
077: 2,
078: new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
079: BasicStroke.JOIN_ROUND, 1.0f, new float[] {
080: 2.0f, 6.0f }, 0.0f));
081:
082: // label data points with values...
083: // plot.setItemsabelsVisible(true);
084:
085: // add a range marker...
086: plot.addRangeMarker(new ValueMarker(8.0));
087:
088: // customise the renderer...
089: LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot
090: .getRenderer();
091: renderer.setDrawOutlines(true);
092: renderer.setItemLabelsVisible(true);
093:
094: // customise the domain axis...
095: CategoryAxis domainAxis = plot.getDomainAxis();
096: CategoryLabelPosition position = new CategoryLabelPosition(
097: RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
098: TextAnchor.TOP_RIGHT, -70,
099: CategoryLabelWidthType.RANGE, 70);
100: domainAxis
101: .setCategoryLabelPositions(new CategoryLabelPositions(
102: position, position, position, position));
103: domainAxis.setCategoryLabelPositionOffset(1);
104:
105: // customise the range axis...
106: NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
107: rangeAxis.setStandardTickUnits(NumberAxis
108: .createIntegerTickUnits());
109: rangeAxis.setAutoRangeIncludesZero(false);
110: rangeAxis.setUpperMargin(0.12);
111:
112: // OPTIONAL CUSTOMISATION COMPLETED.
113:
114: // add the chart to a panel...
115: ChartPanel chartPanel = new ChartPanel(chart);
116: chartPanel.setPreferredSize(getSize());
117: add(chartPanel);
118:
119: }
120: }
|