Provide the app's figure handle in your call to datacursormode.
The window DisplayStyle is not supported in UIfigures.
The default value to SnapToDataVertex is on so you don't need to include that.
dcm_obj = datacursormode(app.MyAppUIFigure);
dcm_obj.Enable = 'on';
update
In 2019b, after executing the lines above if the mouse hovers over a data point and creates a data tip, the following warning appears. Apparently this functionality hasn't been rolled out yet. Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Error using matlab.ui.Figure/set
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App Designer.
Error in setptr (line 386)
An alternative would be to use the data tips by hovering the mouse over a data point. This code below waits for a data tip to appear and then extracts its coordinates.
tth = findall(app.UIAxes,'Type','hggroup');
delete(tth)
tth = [];
while isempty(tth)
tth = findall(app.UIAxes,'Type','hggroup');
pause(0.1)
end
disp(tth.Position)
Best Answer