Here is my html file.
The event handler is never called for some reason. Neither on Windows Chrome, nor W Firefox.
How can I get selected elements from the parcoords chart?
Thanks!
V
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>.</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="parallel-coordinates-plot"></div>
<script>
// Sample data
const data = [
{ A: 1, B: 2, C: 3, D: 4 },
{ A: 2, B: 3, C: 1, D: 5 },
{ A: 3, B: 1, C: 2, D: 4 },
];
const container = document.getElementById('parallel-coordinates-plot');
const dimensions = Object.keys(data[0]);
const trace = {
type: 'parcoords',
line: { color: 'blue' },
dimensions: dimensions.map(dim => ({
label: dim,
values: data.map(d => d[dim])
}))
};
const plotData = [trace];
const layout = {
width: 800,
height: 400,
margin: { t: 40, l: 40, r: 40, b: 40 }
};
Plotly.newPlot(container, plotData, layout);
console.log('newPlot created');
// ^^^ this msg is printed
container.on('plotly_selected', function(eventData) {
console.log("container.on('plotly_selected'");
// ^^^ this msg is never printed
// the rest is moot
const selectedData = eventData.points.map(point => data[point.pointIndex]);
console.log('Selected Data:', selectedData);
});
</script>
</body>
</html>