Android & Xamarin.Android Charting Documentation - SciChart Android Charts SDK v2.x
Tutorial 05 - Adding Tooltips and Legends

This article is a continuation of a tutorial series on how to create a chart using SciChart Android. So far we have created a new chart, added both X axis and Y axis, some series with data and also some zoom and pan behaviors. The previous tutorial can be found here: Tutorial 04 - Adding Zooming, Panning Behavior.

Adding a Chart Legend to the Chart

In SciChart, a chart legend can be created and configured via the LegendModifier:

Copy Code
// Create a LegendModifier and configure a chart legend
ModifierGroup legendModifier = sciChartBuilder.newModifierGroup()
        .withLegendModifier()
        .withOrientation(Orientation.HORIZONTAL)
        .withPosition(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 10)
        .build()
        .build();

// Add the LegendModifier to the SciChartSurface
surface.getChartModifiers().add(legendModifier);

Adding Series Tooltips

Similarly, to add series tooltips you have to create a corresponding modifier and add it to the ChartModifiers collection of a SciChartSurface. In this tutorial, we are going to add a CursorModifier to the chart:

Copy Code
// Create and configure a CursorModifier
ModifierGroup cursorModifier = sciChartBuilder.newModifierGroup()
        .withCursorModifier().withShowTooltip(true).build()
        .build();

// Add the CursorModifier to the SciChartSurface
surface.getChartModifiers().add(cursorModifier);

CursorModifier adds a crosshair onto a SciChartSurface which can show series values in tooltips and chart coordinates at the intersection point:

Further Reading

To learn more about cursors and legends in SciChart please find links to the corresponding documentation articles below:

See Also