admin管理员组文章数量:1332873
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.
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.
Share Improve this question asked Feb 4, 2016 at 10:25 IgnasiIgnasi 6312 gold badges10 silver badges24 bronze badges1 Answer
Reset to default 10You 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./', 'https://google./'];
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>
本文标签: javascriptPlotly Scatterplot hyperlink when point is clickedStack Overflow
版权声明:本文标题:javascript - Plotly Scatterplot hyperlink when point is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742310848a2450838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论