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.renderer.category.LineAndShapeRenderer; 7 import org.jfree.chart.axis.*; 8 import org.jfree.chart.plot.CategoryPlot; 9 import org.jfree.chart.plot.Marker; 10 import org.jfree.chart.plot.ValueMarker; 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 16 import java.awt.*; 17 18 import com.calipso.reportgenerator.common.LanguageTraslator; 19 20 23 24 public class LineChart extends Charts{ 25 26 27 35 public LineChart(CategoryDataset dataset, String tittle, Color color, boolean legend, boolean toolTips, Dimension size, boolean multipleAxis) { 36 super(dataset, tittle, color, legend, toolTips, size, multipleAxis); 37 previewLineChart(); 38 this.setVisible(true); 39 } 40 41 45 void previewLineChart(){ 46 47 48 JFreeChart chart = ChartFactory.createLineChart(tittle, LanguageTraslator.traslate("336"), LanguageTraslator.traslate("337"), dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, 54 legend, toolTips, true ); 58 59 61 chart.setBackgroundPaint(color); 62 63 CategoryPlot plot = chart.getCategoryPlot(); 64 65 plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, 67 BasicStroke.CAP_ROUND, 68 BasicStroke.JOIN_ROUND, 69 1.0f, 70 new float[] { 10.0f, 6.0f }, 71 0.0f)); 72 plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, 73 BasicStroke.CAP_ROUND, 74 BasicStroke.JOIN_ROUND, 75 1.0f, 76 new float[] { 6.0f, 6.0f }, 77 0.0f)); 78 plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, 79 BasicStroke.CAP_ROUND, 80 BasicStroke.JOIN_ROUND, 81 1.0f, 82 new float[] { 2.0f, 6.0f }, 83 0.0f)); 84 85 88 plot.addRangeMarker(new ValueMarker(8.0)); 90 91 LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); 93 renderer.setDrawOutlines(true); 94 renderer.setItemLabelsVisible(true); 95 96 CategoryAxis domainAxis = plot.getDomainAxis(); 98 CategoryLabelPosition position = new CategoryLabelPosition( 99 RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT,-70, CategoryLabelWidthType.RANGE, 100 70); 101 domainAxis.setCategoryLabelPositions(new CategoryLabelPositions(position,position,position,position)); 102 domainAxis.setCategoryLabelPositionOffset(1); 103 104 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 106 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 107 rangeAxis.setAutoRangeIncludesZero(false); 108 rangeAxis.setUpperMargin(0.12); 109 110 111 113 ChartPanel chartPanel = new ChartPanel(chart); 115 chartPanel.setPreferredSize(getSize()); 116 add(chartPanel); 117 118 } 119 } 120 121 122 | Popular Tags |