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.

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