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.Legend; 44 import org.jfree.chart.StandardLegend; 45 import org.jfree.chart.axis.NumberAxis; 46 import org.jfree.chart.plot.PlotOrientation; 47 import org.jfree.data.XYDataset; 48 import org.jfree.ui.ApplicationFrame; 49 import org.jfree.ui.RefineryUtilities; 50 51 56 public class ScatterPlotDemo extends ApplicationFrame { 57 58 63 public ScatterPlotDemo(String title) { 64 65 super(title); 66 XYDataset data = new SampleXYDataset2(); 67 JFreeChart chart = ChartFactory.createScatterPlot( 68 "Scatter Plot Demo", 69 "X", "Y", 70 data, 71 PlotOrientation.VERTICAL, 72 true, 73 true, 74 false 75 ); 76 Legend legend = chart.getLegend(); 77 if (legend instanceof StandardLegend) { 78 StandardLegend sl = (StandardLegend) legend; 79 sl.setDisplaySeriesShapes(true); 80 } 81 NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); 82 domainAxis.setAutoRangeIncludesZero(false); 83 ChartPanel chartPanel = new ChartPanel(chart); 84 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 85 chartPanel.setVerticalAxisTrace(true); 86 chartPanel.setHorizontalAxisTrace(true); 87 chartPanel.setVerticalZoom(true); 88 chartPanel.setHorizontalZoom(true); 89 setContentPane(chartPanel); 90 91 } 92 93 104 109 public static void main(String [] args) { 110 111 ScatterPlotDemo demo = new ScatterPlotDemo("Scatter Plot Demo"); 112 demo.pack(); 113 RefineryUtilities.centerFrameOnScreen(demo); 114 demo.setVisible(true); 115 116 } 117 118 } 119 | Popular Tags |