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