1 37 38 package org.jfree.chart.demo; 39 40 import org.jfree.chart.ChartFactory; 41 import org.jfree.chart.ChartPanel; 42 import org.jfree.chart.JFreeChart; 43 import org.jfree.chart.axis.NumberAxis; 44 import org.jfree.chart.plot.PlotOrientation; 45 import org.jfree.chart.plot.XYPlot; 46 import org.jfree.data.XYZDataset; 47 import org.jfree.ui.ApplicationFrame; 48 import org.jfree.ui.RefineryUtilities; 49 50 55 public class BubblePlotDemo extends ApplicationFrame { 56 57 62 public BubblePlotDemo(String title) { 63 64 super(title); 65 XYZDataset data = new SampleXYZDataset(); 66 JFreeChart chart = createChart(data); 67 68 ChartPanel chartPanel = new ChartPanel(chart); 69 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 70 chartPanel.setVerticalZoom(true); 71 chartPanel.setHorizontalZoom(true); 72 setContentPane(chartPanel); 73 74 } 75 76 83 private JFreeChart createChart(XYZDataset dataset) { 84 JFreeChart chart = ChartFactory.createBubbleChart( 85 "Bubble Plot Demo", 86 "X", 87 "Y", 88 dataset, 89 PlotOrientation.VERTICAL, 90 true, 91 true, 92 false 93 ); 94 XYPlot plot = chart.getXYPlot(); 95 plot.setForegroundAlpha(0.65f); 96 97 NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); 100 domainAxis.setLowerMargin(0.15); 101 domainAxis.setUpperMargin(0.15); 102 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 103 rangeAxis.setLowerMargin(0.15); 104 rangeAxis.setUpperMargin(0.15); 105 return chart; 106 } 107 108 119 124 public static void main(String [] args) { 125 126 BubblePlotDemo demo = new BubblePlotDemo("Bubble Plot Demo"); 127 demo.pack(); 128 RefineryUtilities.centerFrameOnScreen(demo); 129 demo.setVisible(true); 130 131 } 132 133 } 134 | Popular Tags |