Is it possible to link all/some of the points of a scatter plotly plot so whenever you click on them a new tab is opened and the hyperlink linked on that point is fired?
I am using plotly within a Django webserver implementation, this means that plotly is rendered with javascript.
You can use the click handler to implement this. But it may be hard to open in new tab, given most browsers try to prevent popups at all times.
var trace1 = {
x: [1, 2, 3],
y: [1, 6, 3],
mode: 'markers',
type: 'scatter',
text: ['Plotly', 'StackOverflow', 'Google'],
hoverinfo: 'text',
marker: { size: 12 }
};
var links = ['https://plot.ly/', 'http://stackoverflow.com/', 'https://google.com/'];
var data = [ trace1 ];
var layout = {
title:'Hyperlinked points'
};
var myPlot = document.getElementById('myDiv');
Plotly.newPlot(myPlot, data, layout);
myPlot.on('plotly_click', function(data){
if (data.points.length === 1) {
var link = links[data.points[0].pointNumber];
// Note: window navigation here.
window.location = link;
}
});
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="myDiv" style="width: 480px; height: 300px;"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With