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.plot.PlotOrientation; 49 import org.jfree.data.CategoryDataset; 50 import org.jfree.data.xml.DatasetReader; 51 import org.jfree.ui.ApplicationFrame; 52 import org.jfree.ui.RefineryUtilities; 53 54 60 public class XMLBarChartDemo extends ApplicationFrame { 61 62 67 public XMLBarChartDemo(String title) { 68 69 super(title); 70 71 CategoryDataset dataset = null; 73 URL url = getClass().getResource("/org/jfree/chart/demo/categorydata.xml"); 74 75 try { 76 InputStream in = url.openStream(); 77 dataset = DatasetReader.readCategoryDatasetFromXML(in); 78 } 79 catch (IOException ioe) { 80 System.out.println(ioe.getMessage()); 81 } 82 83 JFreeChart chart = ChartFactory.createBarChart( 85 "Bar Chart", "Domain", 87 "Range", 88 dataset, PlotOrientation.VERTICAL, 90 true, true, 92 false 93 ); 94 95 chart.setBackgroundPaint(Color.yellow); 97 98 ChartPanel chartPanel = new ChartPanel(chart); 100 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 101 setContentPane(chartPanel); 102 103 } 104 105 116 121 public static void main(String [] args) { 122 123 XMLBarChartDemo demo = new XMLBarChartDemo("XML Bar Chart Demo"); 124 demo.pack(); 125 RefineryUtilities.centerFrameOnScreen(demo); 126 demo.setVisible(true); 127 128 } 129 130 } 131 | Popular Tags |