SciChart Android 3D Charts API > ChartModifier 3D API > Cursors, Tooltips and Legends > Tooltip Modifier 3D
Tooltip Modifier 3D

Tooltips in SciChart3D are performed by the TooltipModifier3D. This is a ChartModifierBase3D derived type which executes on touch over the data point and shows tooltips for the data-points under the pointer.

 

Declaring a TooltipModifier3D

Declaring a TooltipModifier3D is as simple as adding one to the SciChart3DSurface.ChartModifiers property. This can be done as a single modifier, or as part of a ModifierGroup3D.

Declaring Modifier
Copy Code
final TooltipModifier3D tooltipModifier3D = new TooltipModifier3D();
tooltipModifier3D.setIsEnabled(true);
tooltipModifier3D.setExecuteOnPointerCount(1);
tooltipModifier3D.setCrosshairMode(CrosshairMode.Lines);
surface3d.getChartModifiers().add(new ModifierGroup3D(tooltipModifier3D));

Styling the Tooltip Item

The tooltip item can be customized by setting custom ISeriesInforProvider3D which returns tooltip with desired appearance for desired 3D renderable series. For ScatterRenderableSeries3D code will look like this:

Extend DefaultXyzSeriesInfo3DProvider with custom tooltip
Copy Code
class CustomSeriesInfo3DProvider extends DefaultXyzSeriesInfo3DProvider {
    @Override
    protected ISeriesTooltip3D getSeriesTooltipInternal(Context context, XyzSeriesInfo3D<? extends XyzRenderableSeries3DBase> seriesInfo, Class<?> modifierType) {
        if(modifierType == TooltipModifier3D.class) {
            return new CustomXyzSeriesTooltip3D(context, seriesInfo);
        } else {
            return super.getSeriesTooltipInternal(context, seriesInfo, modifierType);
        }
    }
    private static class CustomXyzSeriesTooltip3D extends XyzSeriesTooltip3D {
        public CustomXyzSeriesTooltip3D(Context context, XyzSeriesInfo3D<?> seriesInfo) {
            super(context, seriesInfo);
        }
        @Override
        protected void internalUpdate(XyzSeriesInfo3D<?> seriesInfo) {
            final SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append("This is Custom Tooltip").append(NEW_LINE);
            sb.append("VertexId: ").append(Integer.toString(seriesInfo.vertexId)).append(NEW_LINE);
            sb.append("X: ").append(seriesInfo.getFormattedXValue()).append(NEW_LINE);
            sb.append("Y: ").append(seriesInfo.getFormattedYValue()).append(NEW_LINE);
            sb.append("Z: ").append(seriesInfo.getFormattedZValue());
            setText(sb);
            setSeriesColor(seriesInfo.seriesColor);
        }
    }
}

Then just need to set it for renderable series:

Setting of custom SeriesInfor3DProvider
Copy Code
final ScatterRenderableSeries3D scatterRenderableSeries3D = new ScatterRenderableSeries3D();
scatterRenderableSeries3D.setSeriesInfoProvider(new CustomSeriesInfo3DProvider());

Styling the Tooltip Container Style

The tooltip container can be customized by passing layout file which contains custom ITooltipContainer as root element into TooltipModifier3D constructor:

Declare custom container
Copy Code
public class CustomTooltipModifierTooltipContainer extends TooltipModifierTooltip {
    public CustomTooltipModifierTooltipContainer(Context context) {
        super(context);
    }
    public CustomTooltipModifierTooltipContainer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CustomTooltipModifierTooltipContainer(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}

Then create XML layout with this custom container:

example_custom_tooltip_container.xml
Copy Code
<com.scichart.examples.fragments.CustomTooltipModifierTooltipContainer xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:background="@drawable/example_custom_tooltip_background"
    android:layout_height="wrap_content"/>

And finally use it to create TooltipModifier3D:

Custom modifier definition
Copy Code
final TooltipModifier3D tooltipModifier3D = new TooltipModifier3D(new CrossDrawableBehavior<>(TooltipModifier3D.class), R.layout.example_custom_tooltip_container);