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.XYSeries; 47 import org.jfree.data.XYSeriesCollection; 48 import org.jfree.ui.ApplicationFrame; 49 import org.jfree.ui.RefineryUtilities; 50 51 56 public class XYSeriesDemo2 extends ApplicationFrame { 57 58 63 public XYSeriesDemo2(String title) { 64 65 super(title); 66 XYSeries series = new XYSeries("Flat Data"); 67 series.add(1.0, 100.0); 68 series.add(5.0, 100.0); 69 series.add(4.0, 100.0); 70 series.add(12.5, 100.0); 71 series.add(17.3, 100.0); 72 series.add(21.2, 100.0); 73 series.add(21.9, 100.0); 74 series.add(25.6, 100.0); 75 series.add(30.0, 100.0); 76 XYSeriesCollection data = new XYSeriesCollection(series); 77 JFreeChart chart = ChartFactory.createXYLineChart( 78 "XY Series Demo 2", 79 "X", 80 "Y", 81 data, 82 PlotOrientation.VERTICAL, 83 true, 84 true, 85 false 86 ); 87 88 XYPlot plot = (XYPlot) chart.getPlot(); 89 NumberAxis axis = (NumberAxis) plot.getRangeAxis(); 90 axis.setAutoRangeIncludesZero(false); 91 axis.setAutoRangeMinimumSize(1.0); 92 ChartPanel chartPanel = new ChartPanel(chart); 93 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 94 setContentPane(chartPanel); 95 96 } 97 98 109 114 public static void main(String [] args) { 115 116 XYSeriesDemo2 demo = new XYSeriesDemo2("XY Series Demo 2"); 117 demo.pack(); 118 RefineryUtilities.centerFrameOnScreen(demo); 119 demo.setVisible(true); 120 121 } 122 123 } 124 | Popular Tags |