3D Hover Options in JavaScript

How to customize hover options for 3d charts.


Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.

By default, Plotly's 3D plots display lines called "spikelines" while hovering over a point. These lines project from the hover point to each of the three axes' normal planes and then extend from those projection data points to the planes' wall boundaries.

function getrandom(num , mul) 
	{
	 var value = [ ];
	 for(i=0;i<=num;i++)
	 {
	  var rand = Math.random() * mul;
	  value.push(rand);
	 }
	 return value;
	}


var data=[
    {
     opacity:0.4,
     type: 'scatter3d',
     x: getrandom(50 , -75),
     y: getrandom(50 , -75),
     z: getrandom(50 , -75),
    },
];
var layout = {
  scene:{
    xaxis: {
		 spikecolor: '#1fe5bd',
		 spikesides: false,
		 spikethickness: 6
  	 	},
  	 yaxis: {
		 spikecolor: '#1fe5bd',
		 spikesides: false,
		 spikethickness: 6
  		},
  	 zaxis: {
		 spikecolor: '#1fe5bd',
		 spikethickness: 6
  		}
  },
};
Plotly.newPlot('myDiv', data, layout);
  
</script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"function getrandom(num , mul) \n\t{\n\t var value = [ ];\n\t for(i=0;i<=num;i++)\n\t {\n\t var rand = Math.random() * mul;\n\t value.push(rand);\n\t }\n\t return value;\n\t}\n\n\nvar data=[\n {\n opacity:0.4,\n type: 'scatter3d',\n x: getrandom(50 , -75),\n y: getrandom(50 , -75),\n z: getrandom(50 , -75),\n },\n];\nvar layout = {\n scene:{\n xaxis: {\n\t\t spikecolor: '#1fe5bd',\n\t\t spikesides: false,\n\t\t spikethickness: 6\n \t \t},\n \t yaxis: {\n\t\t spikecolor: '#1fe5bd',\n\t\t spikesides: false,\n\t\t spikethickness: 6\n \t\t},\n \t zaxis: {\n\t\t spikecolor: '#1fe5bd',\n\t\t spikethickness: 6\n \t\t}\n },\n};\nPlotly.newPlot('myDiv', data, layout);\n "}">

In addition to spikelines, Plotly 3D Surface plots also display surface contours on hover by default. These are customized by styling the contours attribute in the surface trace.

x = [10,20,30,40]
y = [0,1,2,3]
z = [
	[2,2,2,3],
	[1,1,1,1],
	[1,1,0,0],
	[0,0,0,0]
];

var data=[
    {
     opacity:0.9,
     type: 'surface',
     x:x, y:y, z:z,
	  contours: {
		 x: {
			 highlight: true,
			 highlightcolor: "#41a7b3"
         },
		 y: { highlight: false },
		 z: { highlight: false}
	}
    },
];
var layout = {
  scene:{
    xaxis: { showspikes: false },
    yaxis: { showspikes: false },
    zaxis: { showspikes: false }
  },
};
Plotly.newPlot('myDiv', data, layout);
  
</script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"x = [10,20,30,40]\ny = [0,1,2,3]\nz = [\n\t[2,2,2,3],\n\t[1,1,1,1],\n\t[1,1,0,0],\n\t[0,0,0,0]\n];\n\nvar data=[\n {\n opacity:0.9,\n type: 'surface',\n x:x, y:y, z:z,\n\t contours: {\n\t\t x: {\n\t\t\t highlight: true,\n\t\t\t highlightcolor: \"#41a7b3\"\n },\n\t\t y: { highlight: false },\n\t\t z: { highlight: false}\n\t}\n },\n];\nvar layout = {\n scene:{\n xaxis: { showspikes: false },\n yaxis: { showspikes: false },\n zaxis: { showspikes: false }\n },\n};\nPlotly.newPlot('myDiv', data, layout);\n "}">