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.
- Ray Hung asked 7 years ago
- You must login to post comments
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
- Yura Khariton answered 7 years ago
- last edited 7 years ago
-
Thanks :)
- You must login to post comments
Please login first to submit.