问题
Is it possible to configure a plotly plot so that the user is taken to a specific url when they click on a certain data point?
My intended usage is for bar charts: I'd like to be able to click on a bar and then be taken to a url, each bar being configured with a different url.
I'm using plotly python offline to create a <div> which I'm embedding in a website.
Is this possible with the postMessage API on plotly python offline mode?
回答1:
Here I have created an example for you to edit here - right now it has the bars defined Bar1 Bar2 Bar3 Bar4 which indexes a URL for each in the JavaScript code (edit to your liking). In order to use the PostMessage API the barchart you made has to be embedded in an iframe (see how to do it in the codepen link HTML section) and the JavaScript has to be included (on the right pane in the codepen link).
Full running example: http://codepen.io/mslezak/pen/ZWxMBP
Plotly chart embedded: https://plot.ly/~mslezak/11/y-vs-x/
来源:https://stackoverflow.com/questions/36401538/plotly-python-offline-visit-url-on-click