1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.Color ; 41 import java.io.IOException ; 42 import java.io.InputStream ; 43 import java.net.URL ; 44 45 import org.jfree.chart.ChartFactory; 46 import org.jfree.chart.ChartPanel; 47 import org.jfree.chart.JFreeChart; 48 import org.jfree.chart.labels.StandardPieItemLabelGenerator; 49 import org.jfree.chart.plot.PiePlot; 50 import org.jfree.data.PieDataset; 51 import org.jfree.data.xml.DatasetReader; 52 import org.jfree.ui.ApplicationFrame; 53 import org.jfree.ui.RefineryUtilities; 54 55 61 public class XMLPieChartDemo extends ApplicationFrame { 62 63 68 public XMLPieChartDemo(String title) { 69 70 super(title); 71 72 PieDataset dataset = null; 74 URL url = getClass().getResource("/org/jfree/chart/demo/piedata.xml"); 75 76 try { 77 InputStream in = url.openStream(); 78 dataset = DatasetReader.readPieDatasetFromXML(in); 79 } 80 catch (IOException ioe) { 81 System.out.println(ioe.getMessage()); 82 } 83 84 JFreeChart chart = ChartFactory.createPieChart( 86 "Pie Chart Demo 1", dataset, true, true, 90 false 91 ); 92 93 chart.setBackgroundPaint(Color.yellow); 95 PiePlot plot = (PiePlot) chart.getPlot(); 96 plot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS); 97 plot.setNoDataMessage("No data available"); 98 plot.setItemLabelGenerator(new StandardPieItemLabelGenerator()); 99 100 ChartPanel chartPanel = new ChartPanel(chart); 102 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 103 setContentPane(chartPanel); 104 105 } 106 107 118 123 public static void main(String [] args) { 124 125 XMLPieChartDemo demo = new XMLPieChartDemo("XML Pie Chart Demo"); 126 demo.pack(); 127 RefineryUtilities.centerFrameOnScreen(demo); 128 demo.setVisible(true); 129 130 } 131 132 } 133 | Popular Tags |