SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
0
0

Hi,

According to the documentation, in FastCandlestickRenderableSeries

StrokeUp and FillUp styles are applied to bars with Close > Open, and StrokeDown and FillDown to those that have Open <= Close respectively.

I would like to ask is there any method to achieve the following:

The candlestick are green in color when Today Close >= Previous Close and red in color when Today Close < Previous Close

Thanks.

Version
v1.2.1
  • You must to post comments
Great Answer
1
0

Hi Ray,

Unfortunately there is no built-in functionality which allows to do this out of the box. But you can try to use PaletteProvider API and override colors for candles on your own. In this case you’ll need to iterate over points in render pass data and based on its content set desired colors.

I quickly tried to create a prototype of such palette provider so now you have some code to start from:

public class CandlePaletteProvider extends PaletteProviderBase<FastCandlestickRenderableSeries> implements IStrokePaletteProvider, IFillPaletteProvider {

    private final IntegerValues colors = new IntegerValues();

    public CandlePaletteProvider() {
        super(FastCandlestickRenderableSeries.class);
    }

    @Override
    public void update() {
        final OhlcRenderPassData currentRenderPassData = ((FastCandlestickRenderableSeries<?, ?>) renderableSeries).getCurrentRenderPassData();

        final int pointsCount = currentRenderPassData.pointsCount();
        colors.setSize(pointsCount);

        final int[] colorsItems = colors.getItemsArray();
        final double[] closeValues = currentRenderPassData.closeValues.getItemsArray();

        colorsItems[0] = Color.GREEN;
        for (int i = 1; i < pointsCount; i++) {
            colorsItems[i] = closeValues[i] >= closeValues[i-1] ? Color.GREEN : Color.RED;
        }
    }

    @Override
    public final IntegerValues getFillColors() {
        return colors;
    }

    @Override
    public final IntegerValues getStrokeColors() {
        return colors;
    }
}

Hope this will help you!


In v2.x to make this code working you need to replace this line:

final OhlcRenderPassData currentRenderPassData = ((FastCandlestickRenderableSeries<?, ?>) renderableSeries).getCurrentRenderPassData();

on this line (in v2.x we removed generic params from RenderableSeries so you need to cast render pass data):

final OhlcRenderPassData currentRenderPassData = (OhlcRenderPassData) renderableSeries.getCurrentRenderPassData();

Best regards,
Yura

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.