When I move my mouse in a 2D scatter plot, I want to show the corresponding point in a 3D scatter plot. How to do it?
I’m able to do the reverse event, which is linking 3D hover to 2D hover. Not sure why can’t I link 2D to 3D.
I have an error regarding these lines:
myPlot.on('plotly_hover', function (eventdata){
var points = eventdata.points[0],
pointNum = points.pointNumber;
// console.log(points);
Plotly.Fx.hover('myDiv2',[
{ curveNumber:0, pointNumber:pointNum },
]);
});
The error is:
Uncaught TypeError: Cannot read property ‘_subplot’ of undefined
at o (plotly-latest.min.js:58)
at Object.E.hover (plotly-latest.min.js:58)
at n. (link2d3d.html:68)
at n.emit (plotly-latest.min.js:16)
at HTMLDivElement.t.emit (plotly-latest.min.js:53)
at o (plotly-latest.min.js:58)
at Object.E.hover (plotly-latest.min.js:58)
at SVGRectElement.u.onmousemove (plotly-latest.min.js:58)
Here is my code: myDiv is a 2D plot and myDiv2 is a 3D plot.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--PLOTLY-->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
html, body {
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}
#myDiv{
height: 40%;
width: 60%;
position:relative;
}
#myDiv2{
height: 40%;
width: 60%;
position:relative;
}
</style>
</head>
<body class='with-3d-shadow with-transitions'>
<h2>JsonTest</h2>
<div id="myDiv"></div>
<div id="myDiv2"></div>
<script>
var data2d = [
{'marker': {'color': 'FFBAD2', 'line': {'width': 1}},
'mode': 'markers',
'type': 'scatter',
'x': [1, 1, 2, 2],
'y': [1, 2, 1, 2]}
];
var layout = {'title': 'First Plot',
'hovermode':'closest'};
var data3d = [
{'marker': {'color': 'FFBAD2', 'line': {'width': 1}},
'mode': 'markers',
'type': 'scatter3d',
'x': [1, 1, 2, 2],
'y': [1, 2, 1, 2],
'z': [1, 1, 1, 1]}
];
var myPlot = document.getElementById('myDiv');
var myPlot2 = document.getElementById('myDiv2');
Plotly.plot('myDiv', data2d, layout);
Plotly.plot('myDiv2', data3d, layout);
myPlot.on('plotly_hover', function (eventdata){
var points = eventdata.points[0],
pointNum = points.pointNumber;
// console.log(points);
Plotly.Fx.hover('myDiv2',[
{ curveNumber:0, pointNumber:pointNum },
]);
});
myPlot2.on('plotly_hover', function (eventdata){
var points = eventdata.points[0],
pointNum = points.pointNumber;
// console.log(points);
Plotly.Fx.hover('myDiv',[
{ curveNumber:0, pointNumber:pointNum },
]);
});
</script>
</body>
</html>