1 package dinamica.charts; 2 3 import java.awt.Color ; 4 import dinamica.*; 5 import org.jfree.chart.*; 6 import org.jfree.data.category.*; 7 import org.jfree.chart.plot.*; 8 9 14 public class AreaChart extends AbstractChartPlugin 15 { 16 17 20 public JFreeChart getChart(Recordset chartInfo, Recordset data) 21 throws Throwable 22 { 23 24 25 String dateFormat = (String )chartInfo.getValue("dateformat"); 26 27 28 DefaultCategoryDataset chartdata = new DefaultCategoryDataset(); 29 30 31 String series[] = null; 32 String seriesLabels = (String )chartInfo.getValue("title-series"); 33 if (seriesLabels!=null) 34 series = StringUtil.split(seriesLabels, ";"); 35 else 36 { 37 series = new String [1]; 38 series[0] = ""; 39 } 40 41 42 43 String dataCols[] = null; 44 String coly = (String )chartInfo.getValue("column-y"); 45 if (coly.indexOf(";")>0) 46 dataCols = StringUtil.split(coly, ";"); 47 else 48 { 49 dataCols = new String [1]; 50 dataCols[0] = coly; 51 } 52 53 54 55 data.top(); 56 while (data.next()) 57 { 58 59 60 String colx = (String )chartInfo.getValue("column-x"); 61 RecordsetField f = data.getField(colx); 62 String label = null; 63 if (f.getType()==java.sql.Types.DATE) 64 label = StringUtil.formatDate((java.util.Date )data.getValue(colx), dateFormat); 65 else 66 label = String.valueOf(data.getValue(colx)); 67 68 69 for (int i=0;i<dataCols.length;i++) 70 { 71 Double value = new Double (String.valueOf(data.getValue(dataCols[i]))); 72 if (value==null) 73 value = new Double (0); 74 75 chartdata.addValue(value, series[i], label); 76 77 } 78 79 } 80 81 82 String title = (String )chartInfo.getValue("title"); 83 String titlex = (String )chartInfo.getValue("title-x"); 84 String titley = (String )chartInfo.getValue("title-y"); 85 86 87 boolean useLegend = (dataCols.length>1); 88 89 90 JFreeChart chart = ChartFactory.createAreaChart( 91 title, titlex, titley, chartdata, PlotOrientation.VERTICAL, useLegend, false, false ); 100 101 102 configurePlot( chart.getPlot() ); 103 104 String color = chartInfo.getString("color"); 107 if (!useLegend && color!=null) 108 { 109 CategoryPlot p = (CategoryPlot)chart.getPlot(); 110 p.getRenderer().setSeriesPaint(0, Color.decode(color)); 111 } 112 113 114 return chart; 115 116 } 117 118 121 public void configurePlot(Plot p) 122 { 123 124 CategoryPlot plot = (CategoryPlot)p; 125 plot.setBackgroundPaint(Color.WHITE); 126 plot.setRangeGridlinePaint(Color.BLACK); 127 plot.setDomainGridlinePaint(Color.BLACK); 128 plot.setDomainGridlinesVisible(true); 129 plot.setRangeGridlinesVisible(true); 130 plot.setForegroundAlpha(0.6F); 131 132 } 133 134 } 135 | Popular Tags |