1 39 package org.jfree.chart.demo; 40 41 import java.awt.Color ; 42 43 import org.jfree.chart.ChartFactory; 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.axis.LogarithmicAxis; 47 import org.jfree.chart.axis.NumberAxis; 48 import org.jfree.chart.plot.PlotOrientation; 49 import org.jfree.chart.plot.XYPlot; 50 import org.jfree.data.XYSeries; 51 import org.jfree.data.XYSeriesCollection; 52 import org.jfree.ui.ApplicationFrame; 53 import org.jfree.ui.RefineryUtilities; 54 55 60 public class XYLogAxesDemo extends ApplicationFrame { 61 62 67 public XYLogAxesDemo(String title) { 68 69 super(title); 70 71 XYSeries s1 = new XYSeries("Series 1"); 73 XYSeries s2 = new XYSeries("Series 2"); 74 XYSeries s3 = new XYSeries("Series 3"); 75 76 82 for (int i = 1; i <= 50; i++) { 83 s1.add(i, 10 * Math.exp(i / 5.0)); 84 s2.add(i, 20 * Math.exp(i / 5.0)); 85 s3.add(i, 30 * Math.exp(i / 5.0)); 86 } 87 88 XYSeriesCollection dataset = new XYSeriesCollection(); 89 dataset.addSeries(s1); 90 dataset.addSeries(s2); 91 dataset.addSeries(s3); 92 93 JFreeChart chart = ChartFactory.createXYLineChart( 94 "Log Axis Demo", "Category", "Value", dataset, PlotOrientation.VERTICAL, 99 true, true, 101 false 102 ); 103 104 XYPlot plot = chart.getXYPlot(); 105 NumberAxis domainAxis = new NumberAxis("x"); 106 NumberAxis rangeAxis = new LogarithmicAxis("Log(y)"); 107 plot.setDomainAxis(domainAxis); 108 plot.setRangeAxis(rangeAxis); 109 chart.setBackgroundPaint(Color.white); 110 plot.setOutlinePaint(Color.black); 111 ChartPanel chartPanel = new ChartPanel(chart); 112 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 113 setContentPane(chartPanel); 114 115 } 116 117 128 133 public static void main(String [] args) { 134 135 XYLogAxesDemo demo = new XYLogAxesDemo("XY Log Axes Demo"); 136 demo.pack(); 137 RefineryUtilities.centerFrameOnScreen(demo); 138 demo.setVisible(true); 139 140 } 141 142 } 143 | Popular Tags |