Pre loader

Cross Cursor in a candlestick chart

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

Closed
0
0

Greeting, I want to do a custom cursor, something just like the image, but with candles (a candlestick chart) , and I wanna see all the info (Date, open, close, high, low). Is there any example of it?

Version
2.1.0.2210
Images
  • You must to post comments
0
0

Hi Kevin,

Thanks for your question.

Unfortunately we don’t have example of custom series tooltip for candlestick series but it shouldn’t be very hard to build it. Just need to extend another classes ( instead of DefaultXySeriesInfoProvider and XySeriesTooltip classes need to extend DefaultOhlcSeriesInfoProvider and OhlcSeriesTooltip because candlestick series accepts OHLC data ). All required data is provided by OhlcSeriesInfo instance ( Date if you’re using date or category date XAxis and OHLC values ). Here is a code:

class CustomOhlcSeriesInfoProvider extends DefaultOhlcSeriesInfoProvider {
    @Override
    protected ISeriesTooltip getSeriesTooltipInternal(Context context, OhlcSeriesInfo seriesInfo, Class<?> modifierType) {
        if(modifierType == CursorModifier.class) {
            return new CustomOhlcSeriesTooltip(context, seriesInfo); // return custom tooltip for CursorModiifer
        } else {
            return super.getSeriesTooltipInternal(context, seriesInfo, modifierType);
        }
    }

    private static class CustomOhlcSeriesTooltip extends OhlcSeriesTooltip {

        public CustomOhlcSeriesTooltip(Context context, OhlcSeriesInfo seriesInfo) {
            super(context, seriesInfo);
        }

        @Override
        protected void internalUpdate(OhlcSeriesInfo seriesInfo) {
            // define tooltip text
            final SpannableStringBuilder sb = new SpannableStringBuilder();

            if (seriesInfo.seriesName != null) {
                sb.append(seriesInfo.seriesName).append(StringUtil.NEW_LINE);
            }
            sb.append("Date: ").append(seriesInfo.getFormattedXValue());
            sb.append("Open: ").append(seriesInfo.getFormattedOpenValue());
            sb.append("High: ").append(seriesInfo.getFormattedHighValue());
            sb.append("Low: ").append(seriesInfo.getFormattedLowValue());
            sb.append("Close: ").append(seriesInfo.getFormattedCloseValue());

            // set text to display by tooltip
            setText(sb);

            // set tooltip colors
            setTooltipBackgroundColor(0xff6495ed);
            setTooltipStroke(0xff4d81dd);
            setTooltipTextColor(ColorUtil.White);
        }
    }
}

Then like with line series you need to assign custom series info provider when you’re creating candlestick series:

  final FastCandlestickRenderableSeries candlestickSeries = sciChartBuilder.newCandlestickSeries()
            .withSeriesInfoProvider(new CustomOhlcSeriesInfoProvider())
            // other series configuration
            .build();

Hope this will help you!

Best regards,
Yura

  • You must to post comments
Showing 1 result

Try SciChart Today

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

Start TrialCase Studies