Example usage for org.jfree.date SerialDate addMonths

List of usage examples for org.jfree.date SerialDate addMonths

Introduction

In this page you can find the example usage for org.jfree.date SerialDate addMonths.

Prototype

public static SerialDate addMonths(final int months, final SerialDate base) 

Source Link

Document

Creates a new date by adding the specified number of months to the base date.

Usage

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

/**
 * A demonstration application showing how to...
 *
 * @param title  the frame title.//from w  ww.j a  v  a2  s  .c om
 */
public TimeSeriesDemo11(final String title) {

    super(title);
    final JPanel panel = new JPanel(new GridLayout(2, 2));
    panel.setPreferredSize(new java.awt.Dimension(800, 600));

    final Day today = new Day();
    final XYDataset dataset = createDataset("Series 1", 100.0, today, 365);

    final JFreeChart chart1 = createChart("Chart 1 : 1 Year", dataset);
    final ChartPanel chartPanel1 = new ChartPanel(chart1);
    panel.add(chartPanel1);

    final JFreeChart chart2 = createChart("Chart 2 : 6 Months", dataset);
    final SerialDate t = today.getSerialDate();
    final SerialDate t6m = SerialDate.addMonths(-6, t);
    final Day sixMonthsAgo = new Day(t6m);
    final DateAxis axis2 = (DateAxis) chart2.getXYPlot().getDomainAxis();
    axis2.setRange(sixMonthsAgo.getStart(), today.getEnd());
    final ChartPanel chartPanel2 = new ChartPanel(chart2);
    panel.add(chartPanel2);

    final JFreeChart chart3 = createChart("Chart 3 : 3 Months", dataset);
    final SerialDate t3m = SerialDate.addMonths(-3, t);
    final Day threeMonthsAgo = new Day(t3m);
    final DateAxis axis3 = (DateAxis) chart3.getXYPlot().getDomainAxis();
    axis3.setRange(threeMonthsAgo.getStart(), today.getEnd());
    final ChartPanel chartPanel3 = new ChartPanel(chart3);
    panel.add(chartPanel3);

    final JFreeChart chart4 = createChart("Chart 4 : 1 Month", dataset);
    final SerialDate t1m = SerialDate.addMonths(-1, t);
    final Day oneMonthsAgo = new Day(t1m);
    final DateAxis axis4 = (DateAxis) chart4.getXYPlot().getDomainAxis();
    axis4.setRange(oneMonthsAgo.getStart(), today.getEnd());
    final ChartPanel chartPanel4 = new ChartPanel(chart4);
    panel.add(chartPanel4);

    setContentPane(panel);

}