Pre loader

Candlestick chart stroke styling

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

Hi, I would like to make styling on the candlestick stroke of each tick by different situation, like if open > close show red stroke and on reverse in blue color stoke.

I have extended the PaletteProviderBase and implemented the IStrokePaletteProvider and IFillPaletteProvider interface, it seems that it always render the black stroke, but the filled color was correct as expected. Is there any way to custom the stroke color by case? Thanks!

I use the same approach as this suggested (candlestick-chart-coloring) , it seems in 2.0.0 cannot style the stroke as this way.

Version
2.0.0
  • You must to post comments
0
0

Hi May Lun,

I’ve tried to adapt the code from the question which you referenced so it could be used in v2.0. You need to change one line to make it work, just replace:

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

on

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

The rest of code should be the same. Here is an entire code of PaletteProvider:

    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 = (OhlcRenderPassData) 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;
    }
}

Edit: To demonstrate how to use this code I modified candlestick chart example from our demo application:

  @Override
protected void initExample() {
    PriceSeries priceSeries = DataManager.getInstance().getPriceDataIndu(getActivity());

    IOhlcDataSeries<Date, Double> dataSeries = new OhlcDataSeries<>(Date.class, Double.class);
    dataSeries.append(priceSeries.getDateData(), priceSeries.getOpenData(), priceSeries.getHighData(), priceSeries.getLowData(), priceSeries.getCloseData());

    int size = priceSeries.size();
    final IAxis xAxis = sciChartBuilder.newCategoryDateAxis().withVisibleRange(size - 30, size).withGrowBy(0, 0.1).build();
    final IAxis yAxis = sciChartBuilder.newNumericAxis().withGrowBy(0d, 0.1d).withAutoRangeMode(AutoRange.Always).build();

    final FastCandlestickRenderableSeries candlestickSeries = sciChartBuilder.newCandlestickSeries()
            .withPaletteProvider(new CandlePaletteProvider())
            .withDataSeries(dataSeries)
            .build();

    UpdateSuspender.using(surface, new Runnable() {
        @Override
        public void run() {
            Collections.addAll(surface.getRenderableSeries(), candlestickSeries);
            Collections.addAll(surface.getXAxes(), xAxis);
            Collections.addAll(surface.getYAxes(), yAxis);

            surface.getChartModifiers().add(sciChartBuilder.newModifierGroupWithDefaultModifiers().build());
        }
    });
}

Hope this will help you!

Best regards,
Yura

Images
  • may lym
    Thanks for your reply Yura. I have tried the method you suggested or directly replace the code you provided, but it seems the candle stick still only color the candle inside(fill) and the stroke keeps in black color. Is there any setting I should do before applying the CandlePaletteProvider when defining the series.
  • Yura Khariton
    I want to notify you that I investigated this issue. It was caused by a bug in our pen provider for FastCandlestickSeries but it should be fixed now. You can get fix from our Maven repository ( v2.0.1.1949 ). You can find information about how to reference SciChart Android from Maven in this article from our documentation – https://www.scichart.com/documentation/android/v2.x/webframe.html#Tutorial%2001%20-%20Adding%20SciChart%20libraries%20as%20dependencies.html
  • may lym
    Thanks Yura. I have tried the 2.0.1.1949 built with the code. It seems this issue keeps on this built.
  • Yura Khariton
    That’s strange. I just tried to clone our demo application which uses latest version from Github(https://github.com/ABTSoftware/SciChart.Android.Examples), modified one of our examples with FastcandleStickSeries ( I edited my original answer – added modified source code of example and screenshot with results ) and everything worked as it should. Can you try it? If this doesn’t help can you post a project which reproduces this issue?
  • may lym
    Thanks Yura. I try to use the example and it works now.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies