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 LineChart3D 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 = chartInfo.getString("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 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.doubleValue(), 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.createLineChart3D( 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 119 122 public void configurePlot(Plot p) 123 { 124 125 CategoryPlot plot = (CategoryPlot)p; 126 127 plot.setForegroundAlpha(0.5F); 128 plot.setBackgroundPaint(Color.WHITE); 129 plot.setRangeGridlinePaint(Color.BLACK); 130 plot.setDomainGridlinePaint(Color.BLACK); 131 plot.setDomainGridlinesVisible(true); 132 plot.setRangeGridlinesVisible(true); 133 134 135 } 136 137 } 138 | Popular Tags |