01: /* -----------------
02: * LogAxisDemo1.java
03: * -----------------
04: * (C) Copyright 2006, by Object Refinery Limited.
05: */
06:
07: package org.jfree.experimental.chart.demo;
08:
09: import javax.swing.JPanel;
10:
11: import org.jfree.chart.ChartFactory;
12: import org.jfree.chart.ChartPanel;
13: import org.jfree.chart.JFreeChart;
14: import org.jfree.chart.plot.PlotOrientation;
15: import org.jfree.chart.plot.XYPlot;
16: import org.jfree.data.xy.XYDataset;
17: import org.jfree.data.xy.XYSeries;
18: import org.jfree.data.xy.XYSeriesCollection;
19: import org.jfree.experimental.chart.axis.LogAxis;
20: import org.jfree.ui.ApplicationFrame;
21: import org.jfree.ui.RefineryUtilities;
22:
23: /**
24: * A simple demo showing the use of the {@link LogAxis} class.
25: */
26: public class LogAxisDemo1 extends ApplicationFrame {
27:
28: /**
29: * Creates a new instance of the demo.
30: *
31: * @param title the frame title.
32: */
33: public LogAxisDemo1(String title) {
34: super (title);
35: JPanel chartPanel = createDemoPanel();
36: chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
37: setContentPane(chartPanel);
38: }
39:
40: private static JFreeChart createChart(XYDataset dataset) {
41: JFreeChart chart = ChartFactory.createScatterPlot(
42: "Log Axis Demo 1", "X", "Y", dataset,
43: PlotOrientation.VERTICAL, true, true, false);
44: XYPlot plot = (XYPlot) chart.getPlot();
45: LogAxis xAxis = new LogAxis("X");
46: LogAxis yAxis = new LogAxis("Y");
47: plot.setDomainAxis(xAxis);
48: plot.setRangeAxis(yAxis);
49: return chart;
50: }
51:
52: /**
53: * Creates a sample dataset.
54: *
55: * @return A sample dataset.
56: */
57: private static XYDataset createDataset() {
58: XYSeries series = new XYSeries("Random Data");
59: series.add(1.0, 500.2);
60: series.add(5.0, 694.1);
61: series.add(4.0, 100.0);
62: series.add(12.5, 734.4);
63: series.add(17.3, 453.2);
64: series.add(21.2, 500.2);
65: series.add(21.9, 9005.5);
66: series.add(25.6, 734.4);
67: series.add(3000.0, 453.2);
68: return new XYSeriesCollection(series);
69: }
70:
71: /**
72: * Creates a panel for the demo (used by SuperDemo.java).
73: *
74: * @return A panel.
75: */
76: public static JPanel createDemoPanel() {
77: JFreeChart chart = createChart(createDataset());
78: return new ChartPanel(chart);
79: }
80:
81: /**
82: * Starting point for the demonstration application.
83: *
84: * @param args ignored.
85: */
86: public static void main(String[] args) {
87:
88: LogAxisDemo1 demo = new LogAxisDemo1("Log Axis Demo 1");
89: demo.pack();
90: RefineryUtilities.centerFrameOnScreen(demo);
91: demo.setVisible(true);
92:
93: }
94:
95: }
|