Search in sources :

Example 36 with DateAxis

use of org.jfree.chart.axis.DateAxis in project ta4j by ta4j.

the class IndicatorsToChart method main.

public static void main(String[] args) {
    /*
          Getting time series
         */
    TimeSeries series = CsvBarsLoader.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(// title
    "Apple Inc. 2013 Close Prices", // x-axis label
    "Date", // y-axis label
    "Price Per Unit", // data
    dataset, // create legend?
    true, // generate tooltips?
    true, // generate URLs?
    false);
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));
    /*
          Displaying the chart
         */
    displayChart(chart);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.ta4j.core.TimeSeries) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) BollingerBandsLowerIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsLowerIndicator) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) BollingerBandsMiddleIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator) StandardDeviationIndicator(org.ta4j.core.indicators.statistics.StandardDeviationIndicator) BollingerBandsUpperIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) SimpleDateFormat(java.text.SimpleDateFormat) JFreeChart(org.jfree.chart.JFreeChart)

Example 37 with DateAxis

use of org.jfree.chart.axis.DateAxis in project ta4j by ta4j.

the class BuyAndSellSignalsToChart method main.

public static void main(String[] args) {
    // Getting the time series
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();
    // Building the trading strategy
    Strategy strategy = MovingMomentumStrategy.buildStrategy(series);
    /*
          Building chart datasets
         */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));
    /*
          Creating the chart
         */
    JFreeChart chart = ChartFactory.createTimeSeriesChart(// title
    "Bitstamp BTC", // x-axis label
    "Date", // y-axis label
    "Price", // data
    dataset, // create legend?
    true, // generate tooltips?
    true, // generate URLs?
    false);
    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);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) MovingMomentumStrategy(ta4jexamples.strategies.MovingMomentumStrategy) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) SimpleDateFormat(java.text.SimpleDateFormat) JFreeChart(org.jfree.chart.JFreeChart)

Example 38 with DateAxis

use of org.jfree.chart.axis.DateAxis in project zm-mailbox by Zimbra.

the class ChartUtil method lineUpAxes.

/**
 * Updates axes for all charts so that they display the same time interval.
 */
private void lineUpAxes() {
    for (JFreeChart chart : mCharts) {
        XYPlot plot = (XYPlot) chart.getPlot();
        DateAxis axis = (DateAxis) plot.getDomainAxis();
        Date chartMinDate = axis.getMinimumDate();
        Date chartMaxDate = axis.getMaximumDate();
        if (chartMinDate != null && mMinDate < chartMinDate.getTime()) {
            axis.setMinimumDate(new Date(mMinDate));
        }
        if (chartMaxDate != null && mMaxDate > chartMaxDate.getTime()) {
            axis.setMaximumDate(new Date(mMaxDate));
        }
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) XYPlot(org.jfree.chart.plot.XYPlot) JFreeChart(org.jfree.chart.JFreeChart) Date(java.util.Date)

Example 39 with DateAxis

use of org.jfree.chart.axis.DateAxis in project series-rest-api by 52North.

the class ChartIoHandler method configureTimeAxis.

private void configureTimeAxis(XYPlot plot) {
    DateAxis timeAxis = (DateAxis) plot.getDomainAxis();
    final Date start = getStartTime(getTimespan());
    final Date end = getEndTime(getTimespan());
    timeAxis.setRange(start, end);
    final Locale locale = i18n.getLocale();
    IoParameters parameters = getParameters();
    String timeformat = parameters.getTimeFormat();
    DateFormat requestTimeFormat = new SimpleDateFormat(timeformat, locale);
    final DateTimeZone timezone = getTimezone();
    requestTimeFormat.setTimeZone(timezone.toTimeZone());
    timeAxis.setDateFormatOverride(requestTimeFormat);
    timeAxis.setTimeZone(timezone.toTimeZone());
}
Also used : Locale(java.util.Locale) DateAxis(org.jfree.chart.axis.DateAxis) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) IoParameters(org.n52.io.request.IoParameters) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) DateTimeZone(org.joda.time.DateTimeZone)

Aggregations

DateAxis (org.jfree.chart.axis.DateAxis)39 XYPlot (org.jfree.chart.plot.XYPlot)33 JFreeChart (org.jfree.chart.JFreeChart)30 SimpleDateFormat (java.text.SimpleDateFormat)21 NumberAxis (org.jfree.chart.axis.NumberAxis)18 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 Color (java.awt.Color)10 DateFormat (java.text.DateFormat)8 Date (java.util.Date)7 Map (java.util.Map)7 ValueAxis (org.jfree.chart.axis.ValueAxis)7 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)7 BasicStroke (java.awt.BasicStroke)5 TreeMap (java.util.TreeMap)5 DateTickUnit (org.jfree.chart.axis.DateTickUnit)5 TimeSeries (org.jfree.data.time.TimeSeries)5 ChartCompositePart (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartCompositePart)4 HistoryComposite (com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite)4 ShowSetting (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ShowSetting)4