dataTipInteraction

Data tip interaction

Description

A data tip interaction allows you to display data tips within a chart without having to select any buttons in the axes toolbar. To enable data tips, set the Interactions property of the axes to a dataTipInteraction object. When this interaction is enabled, the data tips appear when you hover, click, or tap within the chart.

To enable multiple interactions, set the Interactions property to an array of objects.

Creation

Description

example

d = dataTipInteraction creates a data tip interaction object. With this interaction enabled, clicking or tapping displays a data tip at the nearest data point.

example

d = dataTipInteraction('SnapToDataVertex',snap) specifies whether data tips snap to the nearest data point. When snap is 'off', clicking or tapping displays a data tip at the exact cursor location instead.

Properties

expand all

Display at closest data point, specified as one of these values:

  • 'on' — Display data tip at closest data point.

  • 'off' — Display data tip at cursor location.

Examples

collapse all

Create a surface plot. Get the current axes and replace the default interactions with the data tip and pan interactions. Then hover over the surface to display data tips. Click and drag or tap and drag to pan.

surf(peaks)
ax = gca;
ax.Interactions = [dataTipInteraction panInteraction];

Limitations

The dataTipInteraction function is not supported in the Live Editor.

Tips

  • To customize the content of the data tips, set the DataTipTemplate property of the chart object. For more information, see Create Custom Data Tips.

  • In most cases, the axes have a default set of interactions which depend on the type of chart you are displaying. You can replace the default set with a new set of interactions, but you cannot access or modify any of the interactions in the default set.

Introduced in R2019a