Plotly.d3.csv(
"https://raw.githubusercontent.com/plotly/datasets/master/3d-scatter.csv",
function(err, rows) {
function unpack(rows, key) {
return rows.map(function(row) {
return row[key];
});
}
function setValue(rows, key, color) {
return rows.map(function(row) {
return color;
});
}
var trace1 = {
x: unpack(rows, "x1"),
y: unpack(rows, "y1"),
z: unpack(rows, "z1"),
mode: "markers",
marker: {
color: setValue(rows, "z1", "rgb(127, 230, 127)"),
size: setValue(rows, "z1", 20),
line: {
color: "rgba(217, 217, 217, 0.14)",
width: 0.5
},
opacity: 0.8
},
type: "scatter3d"
};
var trace2 = {
x: unpack(rows, "x2"),
y: unpack(rows, "y2"),
z: unpack(rows, "z2"),
id: unpack(rows, "z2"),
mode: "markers",
marker: {
color: setValue(rows, "z1", "rgb(127, 127, 127)"),
size: setValue(rows, "z1", 20),
symbol: "circle",
line: {
color: "rgb(204, 204, 204)",
width: 1
},
opacity: 0.9
},
type: "scatter3d"
};
var data = [trace1, trace2];
var layout = {
margin: {
l: 0,
r: 0,
b: 0,
t: 0
}
};
Plotly.newPlot("myDiv", data, layout);
var plotly_scatter_div = document.getElementById("myDiv");
var color_select = "#7b3294";
plotly_scatter_div.on("plotly_click", function(data) {
var pn = "",
tn = "",
colors = [];
for (var i = 0; i < data.points.length; i++) {
pn = data.points[i].pointNumber;
tn = data.points[i].curveNumber;
colors = data.points[i].data.marker.color;
}
colors[pn] = color_select;
var update = {
["marker.color[" + pn + "]"]: color_select,
["marker.size[" + pn + "]"]: 7
};
setTimeout(function(x) {
Plotly.restyle("myDiv", update, tn);
}, 50);
});
}
);
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<!-- Plotly chart will be drawn inside this DIV -->
<div id="myDiv" style="width:100%;height:100%"></div>
<script>
/* JAVASCRIPT CODE GOES HERE */
</script>
</body>