Example usage for org.jfree.chart.renderer.xy CandlestickRenderer CandlestickRenderer

List of usage examples for org.jfree.chart.renderer.xy CandlestickRenderer CandlestickRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy CandlestickRenderer CandlestickRenderer.

Prototype

public CandlestickRenderer() 

Source Link

Document

Creates a new renderer for candlestick charts.

Usage

From source file:de.laures.cewolf.taglib.PlotTypes.java

/**
 * Create a renderer for the given type index.
 * We create a new renderer instance for each chart, because they may want to customize
 * it in a post-processor./*from   w  w  w.  j ava 2s.  c o  m*/
 * 
 * @param idx The index of the type
 * @return A new renderer instance
 */
public static AbstractRenderer getRenderer(int idx) {
    switch (idx) {
    case 0:
        return new XYAreaRenderer();
    case 1:
        return new StandardXYItemRenderer();
    case 2:
        return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
    case 3:
        return new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
    case 4:
        return new XYBarRenderer();
    case 5:
        return new XYStepRenderer();
    case 6:
        return new CandlestickRenderer();
    case 7:
        return new HighLowRenderer();
    //case 8: return new SignalRenderer();
    case 9:
        return new BarRenderer();
    case 10:
        return new AreaRenderer();
    case 11:
        return new LineAndShapeRenderer(true, false);
    case 12:
        return new LineAndShapeRenderer(true, true);
    default:
        throw new RuntimeException("Invalid renderer index:" + idx);
    }
}

From source file:com.leonarduk.finance.chart.CandlestickChart.java

public static void displayCandlestickChart(final Stock stock) throws IOException {
    final TimeSeries series = TimeseriesUtils.getTimeSeries(stock, 1);

    /**/* w  w w.j av a  2  s  .co m*/
     * Creating the OHLC dataset
     */
    final OHLCDataset ohlcDataset = CandlestickChart.createOHLCDataset(series);

    /**
     * Creating the additional dataset
     */
    final TimeSeriesCollection xyDataset = CandlestickChart.createAdditionalDataset(series);

    /**
     * Creating the chart
     */
    final JFreeChart chart = ChartFactory.createCandlestickChart(stock.getName() + " price", "Time",
            stock.getCurrency(), ohlcDataset, true);
    // Candlestick rendering
    final CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    final int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    /**
     * Displaying the chart
     */
    ChartDisplay.displayChartInFrame(chart, 740, 300, "Candlestick Chart");
}

From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java

private static JFreeChart createCandlestickChart(OHLCDataset dataset) {
    ValueAxis timeAxis = new DateAxis(xAxisLabel);
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart("Candlestick Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    return chart;
}

From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java

/**
 * Creates a chart./* ww w  .  j a  v a 2 s .  com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The dataset.
 */
private JFreeChart createCandlestickChart(OHLCDataset priceOHLCDataset) {
    final String title = getBestStockName();

    final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date"));
    final NumberAxis valueAxis = new NumberAxis(GUIBundle.getString("ChartJDialog_Price"));
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLowerMargin(0.0);
    XYPlot plot = new XYPlot(priceOHLCDataset, timeAxis, valueAxis, null);

    final CandlestickRenderer candlestickRenderer = new CandlestickRenderer();
    plot.setRenderer(candlestickRenderer);

    // Give good width when zoom in, but too slow in calculation.
    ((CandlestickRenderer) plot.getRenderer()).setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(timeAxis);
    cplot.add(plot, 3);
    cplot.setGap(8.0);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, cplot, true);

    org.yccheok.jstock.charting.Utils.applyChartThemeEx(chart);

    // Handle zooming event.
    chart.addChangeListener(this.getChartChangeListner());

    return chart;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates and returns a default instance of a candlesticks chart.    
 *    /*from  w w  w .java  2 s . c o m*/
 * @param title  the chart title (<code>null</code> permitted).    
 * @param timeAxisLabel  a label for the time axis (<code>null</code>     
 *                       permitted).    
 * @param valueAxisLabel  a label for the value axis (<code>null</code>     
 *                        permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 *    
 * @return A candlestick chart.    
 */
public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel,
        OHLCDataset dataset, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}

From source file:KIDLYFactory.java

/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted)./*  ww  w.j  ava2s  .  c om*/
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel,
        OHLCDataset dataset, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:org.jfree.chart.ChartFactory.java

/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param timeAxisLabel  a label for the time axis ({@code null}
 *                       permitted).//from  ww  w .ja va2s  .  com
 * @param valueAxisLabel  a label for the value axis ({@code null}
 *                        permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel,
        OHLCDataset dataset) {
    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, plot);
    currentTheme.apply(chart);
    return chart;
}