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