1 package dinamica.charts; 2 3 import dinamica.*; 4 import org.jfree.chart.*; 5 import org.jfree.data.general.*; 6 import org.jfree.util.*; 7 import org.jfree.chart.plot.Plot; 8 import org.jfree.chart.plot.RingPlot; 9 import org.jfree.chart.labels.*; 10 11 16 public class RingChart extends AbstractChartPlugin 17 { 18 19 22 public JFreeChart getChart(Recordset chartInfo, Recordset data) 23 throws Throwable 24 { 25 26 27 DefaultPieDataset chartdata = new DefaultPieDataset(); 28 data.top(); 29 while (data.next()) 30 { 31 String colx = (String )chartInfo.getValue("column-x"); 32 String coly = (String )chartInfo.getValue("column-y"); 33 Double value = new Double (String.valueOf(data.getValue(coly))); 34 35 36 String label = String.valueOf(data.getValue(colx)); 37 38 39 if (value==null) 40 value = new Double (0); 41 42 43 chartdata.setValue(label, value.doubleValue()); 44 45 } 46 47 48 String title = (String )chartInfo.getValue("title"); 49 50 51 JFreeChart chart = ChartFactory.createRingChart(title, chartdata, true, false, false); 52 53 54 configurePlot( chart.getPlot() ); 55 56 57 return chart; 58 59 } 60 61 public void configurePlot(Plot p) 62 { 63 64 RingPlot plot = (RingPlot) p; 65 plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}")); 66 plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); 67 plot.setStartAngle(290D); 68 plot.setDirection(Rotation.CLOCKWISE); 69 plot.setForegroundAlpha(0.6F); 70 } 71 72 } 73 | Popular Tags |