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 20 21 public class AreaChart extends Charts { 22 23 24 29 public AreaChart(CategoryDataset dataset, String 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 39 private void previewAreaChart(){ 40 JFreeChart chart = ChartFactory.createAreaChart(tittle, LanguageTraslator.traslate("336"), LanguageTraslator.traslate("337"), dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, 45 legend, toolTips, false ); 49 50 52 56 chart.setBackgroundPaint(color); 57 58 CategoryPlot plot = chart.getCategoryPlot(); 59 plot.setForegroundAlpha(0.5f); 60 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.setLowerMargin(0.0); 74 domainAxis.setUpperMargin(0.0); 75 76 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 77 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 78 80 ChartPanel chartPanel = new ChartPanel(chart); 82 chartPanel.setPreferredSize(getSize()); 83 add(chartPanel); 84 } 85 } 86 | Popular Tags |