{
points: [{
curveNumber: 2, // index in data of the trace associated with the selected point
pointNumber: 2, // index of the selected point
x: 5, // x value
y: 600, // y value
data: {/* */}, // ref to the trace as sent to Plotly.newPlot associated with the selected point
fullData: {/* */}, // ref to the trace including all the defaults
xaxis: {/* */}, // ref to x-axis object (i.e layout.xaxis) associated with the selected point
yaxis: {/* */} // ref to y-axis object " "
}, {
/* similarly for other selected points */
}]
}
By default, plotly_hover fires only when the cursor is over a trace. Set hoveranywhere to true in the layout, and the event also fires over empty plot space.
An event from empty space carries an empty points array. The event reports the cursor position in two forms. xvals and yvals hold data-space coordinates. xPixel and yPixel hold pixels from the top-left corner of the graph div.
plotly_unhover fires once when the cursor leaves the plot area.
var data = [{
x: [1, 2, 3, 4, 5],
y: [2, 4, 3, 5, 4],
type: 'scatter',
mode: 'markers',
marker: {size: 14}
}];
var hoverPrompt = 'Hover anywhere in the plot area';
var layout = {
title: {text: 'Hover Anywhere'},
hovermode: 'closest',
hoveranywhere: true,
annotations: [{
text: hoverPrompt,
xref: 'paper',
yref: 'paper',
x: 0.02,
y: 0.98,
xanchor: 'left',
yanchor: 'top',
showarrow: false
}]
};
Plotly.newPlot('myDiv', data, layout);
var hoverReadout = hoverPrompt;
// Redraw only when the text changes, because plotly_hover fires on every cursor move
function showHoverReadout(text) {
if (text === hoverReadout) return;
hoverReadout = text;
Plotly.relayout('myDiv', {'annotations[0].text': text});
}
document.getElementById('myDiv').on('plotly_hover', function(eventData) {
if (eventData.points.length) {
var point = eventData.points[0];
showHoverReadout('Over a point: x = ' + point.x + ', y = ' + point.y);
} else {
// points is empty over blank space, so read the cursor position from xvals and yvals
showHoverReadout('Empty space: x = ' + eventData.xvals[0].toFixed(2) +
', y = ' + eventData.yvals[0].toFixed(2));
}
});
document.getElementById('myDiv').on('plotly_unhover', function() {
showHoverReadout(hoverPrompt);
});
This is a more complex example that uses both hover, and click events to display traces. Take a look in the codepen javascript!
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.