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?
- Kevin Rodriguez asked 7 years ago
- You must login to post comments
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
- Yura Khariton answered 7 years ago
- It’s perfect, thank you.
- You must login to post comments