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.StandardXYItemRenderer; 47 import org.jfree.data.XYDataset; 48 import org.jfree.data.XYSeries; 49 import org.jfree.data.XYSeriesCollection; 50 import org.jfree.ui.ApplicationFrame; 51 import org.jfree.ui.RefineryUtilities; 52 53 58 public class LineChartDemo3 extends ApplicationFrame { 59 60 65 public LineChartDemo3(String title) { 66 67 super(title); 68 69 XYSeriesCollection dataset = new XYSeriesCollection(); 71 for (int i = 0; i < 10; i++) { 72 XYSeries series = new XYSeries("S" + i); 73 for (int j = 0; j < 10; j++) { 74 series.add(j, Math.random() * 100); 75 } 76 dataset.addSeries(series); 77 } 78 79 JFreeChart chart = createChart(dataset); 80 81 ChartPanel chartPanel = new ChartPanel(chart); 83 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 84 setContentPane(chartPanel); 85 86 } 87 88 99 106 private JFreeChart createChart(XYDataset dataset) { 107 108 JFreeChart chart = ChartFactory.createXYLineChart( 109 "Line Chart Demo 3", "X", "Y", dataset, PlotOrientation.VERTICAL, 114 true, true, false ); 118 119 121 XYPlot plot = chart.getXYPlot(); 123 StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); 124 renderer.setPlotShapes(true); 125 126 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 128 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 129 130 return chart; 131 } 132 133 138 public static void main(String [] args) { 139 140 LineChartDemo3 demo = new LineChartDemo3("Line Chart Demo 3"); 141 demo.pack(); 142 RefineryUtilities.centerFrameOnScreen(demo); 143 demo.setVisible(true); 144 145 } 146 147 } 148 | Popular Tags |