javascript - Plotly Scatterplot hyperlink when point is clicked - Stack Overflow

Is it possible to link allsome of the points of a scatter plotly plot so whenever you click on them a

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 badges
Add a ment  | 

1 Answer 1

Reset to default 10

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./', '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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742310848a4419861.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信