Example usage for org.jfree.chart.plot XYPlot getDomainAxis

List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getDomainAxis.

Prototype

public ValueAxis getDomainAxis() 

Source Link

Document

Returns the domain axis with index 0.

Usage

From source file:javatest.IndicatorsToChart.java

public static void main(String[] args) {

    /**/*from w  ww.jav a  2  s  . c om*/
     * 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) {

    /**/*  w  w  w.  j a  v  a2  s. c o m*/
     * 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.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 w  w  w  .j  a  va  2s .c o  m*/
     * 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: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 w  w  . j ava  2s .  co  m
     * 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: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);

    /**// w w  w .ja va2s  .c  om
     * 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:org.jfree.chart.demo.SparklineDemo1.java

public static void main(String args[]) {
    XYSeries xyseries = new XYSeries("Series 1");
    xyseries.add(1.0D, 1.0D);//from w  w  w  .  ja  v  a2  s  .  c  om
    xyseries.add(2D, 3D);
    xyseries.add(3D, 2D);
    xyseries.add(4D, 4D);
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "X", "Y", xyseriescollection,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setInsets(RectangleInsets.ZERO_INSETS);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinesVisible(false);
    xyplot.setOutlinePaint(null);
    xyplot.getDomainAxis().setVisible(false);
    xyplot.getRangeAxis().setVisible(false);
    try {
        ChartUtilities.saveChartAsPNG(new File("Sparky.png"), jfreechart, 100, 20);
    } catch (IOException ioexception) {
        ioexception.printStackTrace();
    }
}

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);/*from   w  ww.  j a  va2 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:org.jfree.chart.demo.Function2DDemo1.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Function2DDemo1 ", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.getDomainAxis().setLowerMargin(0.0D);
    xyplot.getDomainAxis().setUpperMargin(0.0D);
    return jfreechart;
}

From source file:org.jax.bham.util.JFreeChartUtil.java

/**
 * Convert from a Java2D point to a graph point
 * @param java2DPoint//from   w  w  w .  ja v  a 2s. com
 *          the java 2D point to convert
 * @param chartPanel
 *          the chart panel to convert
 * @return
 *          the point
 */
public static Point2D java2DPointToGraphPoint(Point2D java2DPoint, ChartPanel chartPanel) {
    JFreeChart chart = chartPanel.getChart();
    ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    XYPlot xyPlot = chart.getXYPlot();

    double graphX = xyPlot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea,
            xyPlot.getDomainAxisEdge());
    double graphY = xyPlot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea,
            xyPlot.getRangeAxisEdge());

    return new Point2D.Double(graphX, graphY);
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDirectionDataset(600);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", xydataset, true,
            true, false);/*w w w.jav a  2s . c  o  m*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.getDomainAxis().setLowerMargin(0.0D);
    xyplot.getDomainAxis().setUpperMargin(0.0D);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    TickUnits tickunits = new TickUnits();
    tickunits.add(new NumberTickUnit(180D, new CompassFormat()));
    tickunits.add(new NumberTickUnit(90D, new CompassFormat()));
    tickunits.add(new NumberTickUnit(45D, new CompassFormat()));
    tickunits.add(new NumberTickUnit(22.5D, new CompassFormat()));
    numberaxis.setStandardTickUnits(tickunits);
    xyplot.setRangeAxis(numberaxis);
    XYAreaRenderer xyarearenderer = new XYAreaRenderer();
    NumberAxis numberaxis1 = new NumberAxis("Force");
    numberaxis1.setRange(0.0D, 12D);
    xyarearenderer.setSeriesPaint(0, new Color(0, 0, 255, 128));
    xyplot.setDataset(1, createForceDataset(600));
    xyplot.setRenderer(1, xyarearenderer);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.mapDatasetToRangeAxis(1, 1);
    return jfreechart;
}