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