Java Code Examples for org.jfree.chart.renderer.xy.CandlestickRenderer#setAutoWidthMethod()

The following examples show how to use org.jfree.chart.renderer.xy.CandlestickRenderer#setAutoWidthMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CandlestickRendererTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Check that the equals() method distinguishes all fields.
 */
public void testEquals() {
    CandlestickRenderer r1 = new CandlestickRenderer();
    CandlestickRenderer r2 = new CandlestickRenderer();
    assertEquals(r1, r2);

    // upPaint
    r1.setUpPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
            Color.white));
    assertFalse(r1.equals(r2));
    r2.setUpPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
            Color.white));
    assertTrue(r1.equals(r2));

    // downPaint
    r1.setDownPaint(new GradientPaint(5.0f, 6.0f, Color.green, 7.0f, 8.0f,
            Color.yellow));
    assertFalse(r1.equals(r2));
    r2.setDownPaint(new GradientPaint(5.0f, 6.0f, Color.green, 7.0f, 8.0f,
            Color.yellow));
    assertTrue(r1.equals(r2));

    // drawVolume
    r1.setDrawVolume(false);
    assertFalse(r1.equals(r2));
    r2.setDrawVolume(false);
    assertTrue(r1.equals(r2));

    // candleWidth
    r1.setCandleWidth(3.3);
    assertFalse(r1.equals(r2));
    r2.setCandleWidth(3.3);
    assertTrue(r1.equals(r2));

    // maxCandleWidthInMilliseconds
    r1.setMaxCandleWidthInMilliseconds(123);
    assertFalse(r1.equals(r2));
    r2.setMaxCandleWidthInMilliseconds(123);
    assertTrue(r1.equals(r2));

    // autoWidthMethod
    r1.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    assertFalse(r1.equals(r2));
    r2.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    assertTrue(r1.equals(r2));

    // autoWidthFactor
    r1.setAutoWidthFactor(0.22);
    assertFalse(r1.equals(r2));
    r2.setAutoWidthFactor(0.22);
    assertTrue(r1.equals(r2));

    // autoWidthGap
    r1.setAutoWidthGap(1.1);
    assertFalse(r1.equals(r2));
    r2.setAutoWidthGap(1.1);
    assertTrue(r1.equals(r2));

    r1.setUseOutlinePaint(true);
    assertFalse(r1.equals(r2));
    r2.setUseOutlinePaint(true);
    assertTrue(r1.equals(r2));

    r1.setVolumePaint(Color.blue);
    assertFalse(r1.equals(r2));
    r2.setVolumePaint(Color.blue);
    assertTrue(r1.equals(r2));
}
 
Example 2
Source File: CandlestickRendererTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Check that the equals() method distinguishes all fields.
 */
public void testEquals() {
    CandlestickRenderer r1 = new CandlestickRenderer();
    CandlestickRenderer r2 = new CandlestickRenderer();
    assertEquals(r1, r2);
    
    // upPaint
    r1.setUpPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, 
            Color.white));
    assertFalse(r1.equals(r2));
    r2.setUpPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, 
            Color.white));
    assertTrue(r1.equals(r2));
    
    // downPaint
    r1.setDownPaint(new GradientPaint(5.0f, 6.0f, Color.green, 7.0f, 8.0f, 
            Color.yellow));
    assertFalse(r1.equals(r2));
    r2.setDownPaint(new GradientPaint(5.0f, 6.0f, Color.green, 7.0f, 8.0f, 
            Color.yellow));
    assertTrue(r1.equals(r2));
    
    // drawVolume
    r1.setDrawVolume(false);
    assertFalse(r1.equals(r2));
    r2.setDrawVolume(false);
    assertTrue(r1.equals(r2));
    
    // candleWidth
    r1.setCandleWidth(3.3);
    assertFalse(r1.equals(r2));
    r2.setCandleWidth(3.3);
    assertTrue(r1.equals(r2));
    
    // maxCandleWidthInMilliseconds
    r1.setMaxCandleWidthInMilliseconds(123);
    assertFalse(r1.equals(r2));
    r2.setMaxCandleWidthInMilliseconds(123);
    assertTrue(r1.equals(r2));
    
    // autoWidthMethod
    r1.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    assertFalse(r1.equals(r2));
    r2.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    assertTrue(r1.equals(r2));
    
    // autoWidthFactor
    r1.setAutoWidthFactor(0.22);
    assertFalse(r1.equals(r2));
    r2.setAutoWidthFactor(0.22);
    assertTrue(r1.equals(r2));
    
    // autoWidthGap
    r1.setAutoWidthGap(1.1);
    assertFalse(r1.equals(r2));
    r2.setAutoWidthGap(1.1);
    assertTrue(r1.equals(r2));
    
    r1.setUseOutlinePaint(true);
    assertFalse(r1.equals(r2));
    r2.setUseOutlinePaint(true);
    assertTrue(r1.equals(r2));
    
    r1.setVolumePaint(Color.blue);
    assertFalse(r1.equals(r2));
    r2.setVolumePaint(Color.blue);
    assertTrue(r1.equals(r2));
}
 
Example 3
Source File: CandlestickChart.java    From ta4j-origins with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    /**
     * Getting time series
     */
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();
    
    /**
     * Creating the OHLC dataset
     */
    OHLCDataset ohlcDataset = createOHLCDataset(series);
    
    /**
     * Creating the additional dataset
     */
    TimeSeriesCollection xyDataset = createAdditionalDataset(series);
    
    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createCandlestickChart(
            "Bitstamp BTC price",
            "Time",
            "USD",
            ohlcDataset,
            true);
    // Candlestick rendering
    CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    
    /**
     * Displaying the chart
     */
    displayChart(chart);
}