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.chart.renderer.XYDotRenderer; 47 import org.jfree.data.XYDataset; 48 import org.jfree.ui.ApplicationFrame; 49 import org.jfree.ui.RefineryUtilities; 50 51 56 public class ScatterPlotDemo2 extends ApplicationFrame { 57 58 63 public ScatterPlotDemo2(String title) { 64 65 super(title); 66 XYDataset dataset = new SampleXYDataset2(); 67 JFreeChart chart = createChart(dataset); 68 ChartPanel chartPanel = new ChartPanel(chart); 69 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 70 chartPanel.setVerticalAxisTrace(true); 71 chartPanel.setHorizontalAxisTrace(true); 72 chartPanel.setVerticalZoom(true); 73 chartPanel.setHorizontalZoom(true); 74 setContentPane(chartPanel); 75 76 } 77 78 89 96 private JFreeChart createChart(XYDataset dataset) { 97 JFreeChart chart = ChartFactory.createScatterPlot( 98 "Scatter Plot Demo", 99 "X", "Y", dataset, 100 PlotOrientation.HORIZONTAL, 101 true, false, false ); 105 XYPlot plot = chart.getXYPlot(); 106 plot.setRenderer(new XYDotRenderer()); 107 NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); 108 domainAxis.setAutoRangeIncludesZero(false); 109 return chart; 110 } 111 112 117 public static void main(String [] args) { 118 119 ScatterPlotDemo2 demo = new ScatterPlotDemo2("Scatter Plot Demo 2"); 120 demo.pack(); 121 RefineryUtilities.centerFrameOnScreen(demo); 122 demo.setVisible(true); 123 124 } 125 126 } 127 | Popular Tags |