Example usage for org.jfree.chart ChartFactory createTimeSeriesChart

List of usage examples for org.jfree.chart ChartFactory createTimeSeriesChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createTimeSeriesChart.

Prototype

public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel,
        XYDataset dataset, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates and returns a time series chart.

Usage

From source file:com.jaxzin.iraf.demo.GSDemo.java

public static void main(String[] args) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Timeseries", "", "", createData(), false, true,
            true);//  www  .  j  a  v  a  2  s  . co  m

    // Customize the chart
    customizeChart(chart);

    final JPanel panel = new ChartPanel(chart, true);
    final JFrame frame = new JFrame("Demo");
    frame.getContentPane().add(panel);
    setupJFrame(frame);
}

From source file:de.codesourcery.eve.skills.ui.ChartTest.java

public static void main(String[] args) {

    TimeSeries s1 = new TimeSeries("L&G European Index Trust");
    s1.add(new Day(1, 2, 2001), 181.8);
    s1.add(new Month(3, 2001), 167.3);
    s1.add(new Month(4, 2001), 153.8);
    s1.add(new Month(5, 2001), 167.6);
    s1.add(new Month(6, 2001), 158.8);
    s1.add(new Month(7, 2001), 148.3);
    s1.add(new Month(8, 2001), 153.9);
    s1.add(new Month(9, 2001), 142.7);
    s1.add(new Month(10, 2001), 123.2);
    s1.add(new Month(11, 2001), 131.8);
    s1.add(new Month(12, 2001), 139.6);
    s1.add(new Month(1, 2002), 142.9);
    s1.add(new Month(2, 2002), 138.7);
    s1.add(new Month(3, 2002), 137.3);
    s1.add(new Month(4, 2002), 143.9);
    s1.add(new Month(5, 2002), 139.8);
    s1.add(new Month(6, 2002), 137.0);
    s1.add(new Month(7, 2002), 132.8);
    TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
    s2.add(new Month(2, 2001), 129.6);
    s2.add(new Month(3, 2001), 123.2);
    s2.add(new Month(4, 2001), 117.2);
    s2.add(new Month(5, 2001), 124.1);
    s2.add(new Month(6, 2001), 122.6);
    s2.add(new Month(7, 2001), 119.2);
    s2.add(new Month(8, 2001), 116.5);
    s2.add(new Month(9, 2001), 112.7);
    s2.add(new Month(10, 2001), 101.5);
    s2.add(new Month(11, 2001), 106.1);
    s2.add(new Month(12, 2001), 110.3);
    s2.add(new Month(1, 2002), 111.7);
    s2.add(new Month(2, 2002), 111.0);
    s2.add(new Month(3, 2002), 109.6);
    s2.add(new Month(4, 2002), 113.2);
    s2.add(new Month(5, 2002), 111.6);
    s2.add(new Month(6, 2002), 108.8);
    s2.add(new Month(7, 2002), 101.6);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);//  www.  jav  a  2  s.  c  o m
    dataset.addSeries(s2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    // display chart
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);

    JFrame frame = new JFrame("test");
    frame.setContentPane(chartPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

}

From source file:javatest.IndicatorsToChart.java

public static void main(String[] args) {

    /**/*  w ww. j av a2  s  .co  m*/
     * Getting time series
     */
    TimeSeries series = CsvTicksLoader.loadAppleIncSeries();

    /**
     * Creating indicators
     */
    // Close price
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    // Bollinger bands
    BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(closePrice);
    BollingerBandsLowerIndicator lowBBand = new BollingerBandsLowerIndicator(middleBBand, closePrice);
    BollingerBandsUpperIndicator upBBand = new BollingerBandsUpperIndicator(middleBBand, closePrice);
    SMAIndicator ind = new SMAIndicator(closePrice, 240);
    /**
     * Building chart dataset
     */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, ind, "sms "));
    dataset.addSeries(buildChartTimeSeries(series, closePrice, "close"));
    // dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Neli ist lieb", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));

    /**
     * Displaying the chart
     */
    displayChart(chart);
}

From source file:ta4jexamples.indicators.IndicatorsToChart.java

public static void main(String[] args) {

    /**/*from w w w. j  av  a2 s  .  c  om*/
     * Getting time series
     */
    TimeSeries series = CsvTicksLoader.loadAppleIncSeries();

    /**
     * Creating indicators
     */
    // Close price
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    EMAIndicator avg14 = new EMAIndicator(closePrice, 14);
    StandardDeviationIndicator sd14 = new StandardDeviationIndicator(closePrice, 14);

    // Bollinger bands
    BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(avg14);
    BollingerBandsLowerIndicator lowBBand = new BollingerBandsLowerIndicator(middleBBand, sd14);
    BollingerBandsUpperIndicator upBBand = new BollingerBandsUpperIndicator(middleBBand, sd14);

    /**
     * Building chart dataset
     */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, closePrice, "Apple Inc. (AAPL) - NASDAQ GS"));
    dataset.addSeries(buildChartTimeSeries(series, lowBBand, "Low Bollinger Band"));
    dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Apple Inc. 2013 Close Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));

    /**
     * Displaying the chart
     */
    displayChart(chart);
}

From source file:ta4jexamples.analysis.CashFlowToChart.java

public static void main(String[] args) {

    // Getting the time series
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();
    // Building the trading strategy
    Strategy strategy = MovingMomentumStrategy.buildStrategy(series);
    // Running the strategy
    TimeSeriesManager seriesManager = new TimeSeriesManager(series);
    TradingRecord tradingRecord = seriesManager.run(strategy);
    // Getting the cash flow of the resulting trades
    CashFlow cashFlow = new CashFlow(series, tradingRecord);

    /**//from   w  ww. j av  a2  s.com
     * Building chart datasets
     */
    TimeSeriesCollection datasetAxis1 = new TimeSeriesCollection();
    datasetAxis1
            .addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));
    TimeSeriesCollection datasetAxis2 = new TimeSeriesCollection();
    datasetAxis2.addSeries(buildChartTimeSeries(series, cashFlow, "Cash Flow"));

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", // title
            "Date", // x-axis label
            "Price", // y-axis label
            datasetAxis1, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM-dd HH:mm"));

    /**
     * Adding the cash flow axis (on the right)
     */
    addCashFlowAxis(plot, datasetAxis2);

    /**
     * Displaying the chart
     */
    displayChart(chart);
}

From source file:ta4jexamples.analysis.BuyAndSellSignalsToChart.java

public static void main(String[] args) {

    // Getting the time series
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();
    // Building the trading strategy
    Strategy strategy = MovingMomentumStrategy.buildStrategy(series);

    /**//from ww w  . ja v  a2  s  .c om
     * Building chart datasets
     */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", // title
            "Date", // x-axis label
            "Price", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM-dd HH:mm"));

    /**
     * Running the strategy and adding the buy and sell signals to plot
     */
    addBuySellSignals(series, strategy, plot);

    /**
     * Displaying the chart
     */
    displayChart(chart);
}

From source file:com.leonarduk.finance.analysis.CashFlowToChart.java

public static void main(final String[] args) throws IOException {

    // Getting the time series
    final StockFeed feed = new IntelligentStockFeed();
    final String ticker = "IUKD";
    final Stock stock = feed.get(Instrument.fromString(ticker), 2).get();
    final TimeSeries series = TimeseriesUtils.getTimeSeries(stock, 1);

    // Building the trading strategy
    final AbstractStrategy strategy = MovingMomentumStrategy.buildStrategy(series, 12, 26, 9);

    // Running the strategy
    final TradingRecord tradingRecord = series.run(strategy.getStrategy());
    // Getting the cash flow of the resulting trades
    final CashFlow cashFlow = new CashFlow(series, tradingRecord);

    /**//from w  w w . j  a  v  a  2 s .c  o  m
     * Building chart datasets
     */
    final TimeSeriesCollection datasetAxis1 = new TimeSeriesCollection();
    datasetAxis1.addSeries(CashFlowToChart.buildChartTimeSeries(series, new ClosePriceIndicator(series),
            "Bitstamp Bitcoin (BTC)"));
    final TimeSeriesCollection datasetAxis2 = new TimeSeriesCollection();
    datasetAxis2.addSeries(CashFlowToChart.buildChartTimeSeries(series, cashFlow, "Cash Flow"));

    /**
     * Creating the chart
     */
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", // title
            "Date", // x-axis label
            "Price", // y-axis label
            datasetAxis1, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    final XYPlot plot = (XYPlot) chart.getPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM-dd HH:mm"));

    /**
     * Adding the cash flow axis (on the right)
     */
    CashFlowToChart.addCashFlowAxis(plot, datasetAxis2);

    /**
     * Displaying the chart
     */
    CashFlowToChart.displayChart(chart);
}

From source file:carbon.plot.PlotTimeSeries.java

public static void PlotTS(int yr, double[] ppm, int years, String chartOutput) {

    TimeSeries carbon = new TimeSeries("Carbon");
    for (int i = 0; i < years; i++) {
        carbon.add(new Year(yr + i), ppm[i]);
    }/* w w w.jav  a 2  s. c o m*/
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(carbon);
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Atmospheric CO2 concentration", "Year", "CO2 (ppm)",
            dataset, false, true, true);
    try {
        File plot = new File(chartOutput);
        ChartUtilities.saveChartAsJPEG(plot, chart, 500, 300);
        new DisplayImage(chartOutput);
    } catch (IOException e) {
        System.err.println("Problem creating chart.");
    }
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Exercise Chart", "Elapsed Time",
            "Beats Per Minute", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/*  w  ww. jav  a2 s.  c  o m*/
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    Minute minute = new Minute(0, 9, 1, 10, 2006);
    RelativeDateFormat relativedateformat = new RelativeDateFormat(minute.getFirstMillisecond());
    relativedateformat.setSecondFormatter(new DecimalFormat("00"));
    dateaxis.setDateFormatOverride(relativedateformat);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date",
            "Price Per Unit", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    PeriodAxis periodaxis = new PeriodAxis("Quarter", new Quarter(), new Quarter());
    periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Quarter.class);
    PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[1];
    aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Quarter.class,
            new QuarterDateFormat(TimeZone.getDefault(), QuarterDateFormat.ROMAN_QUARTERS));
    periodaxis.setLabelInfo(aperiodaxislabelinfo);
    xyplot.setDomainAxis(periodaxis);//from   w  ww .j  a v a 2  s.  c om
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }
    return jfreechart;
}