Example usage for org.jfree.chart.axis CyclicNumberAxis CyclicNumberAxis

List of usage examples for org.jfree.chart.axis CyclicNumberAxis CyclicNumberAxis

Introduction

In this page you can find the example usage for org.jfree.chart.axis CyclicNumberAxis CyclicNumberAxis.

Prototype

public CyclicNumberAxis(double period, String label) 

Source Link

Document

Creates a named CycleNumberAxis with the given period.

Usage

From source file:org.jfree.chart.demo.CyclicXYPlotDemo.java

/**
 * A demonstration application showing an XY plot, with a cyclic axis and renderer
 *
 * @param title  the frame title./*from www.j  av a  2  s .  c o  m*/
 */
public CyclicXYPlotDemo(final String title) {

    super(title);

    this.series = new XYSeries("Random Data");
    this.series.setMaximumItemCount(50); // Only 50 items are visible at the same time. 
                                         // Keep more as a mean to test this.
    final XYSeriesCollection data = new XYSeriesCollection(this.series);

    final JFreeChart chart = ChartFactory.createXYLineChart("Cyclic XY Plot Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setDomainAxis(new CyclicNumberAxis(10, 0));
    plot.setRenderer(new CyclicXYItemRenderer());

    final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setAutoRangeMinimumSize(1.0);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(400, 300));
    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel, BorderLayout.CENTER);

    final JButton button1 = new JButton("Start");
    button1.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            timer.start();
        }
    });

    final JButton button2 = new JButton("Stop");
    button2.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            timer.stop();
        }
    });

    final JButton button3 = new JButton("Step by step");
    button3.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            CyclicXYPlotDemo.this.actionPerformed(null);
        }
    });

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    setContentPane(content);

    this.timer = new Timer(200, this);
}