如何向 Google 图表散点图上的每组数据点添加不同的网页链接?
是否可以将超链接添加到散点图,以便当我单击数据点时它会打开链接?
谢谢
Is it possible to add the hyperlinks to the scatter plot, so when I click on a data point it opens the link?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了一个 jsfiddle 演示 来表明可以做到这一点,但我不能找到一种方法以我喜欢的方式去做。
创建数据集后,我创建了一个数组,其中包含 URL 列表,其顺序与显示的结果的顺序相同。当通过单击某个点触发选择事件时,将执行一个函数,在本例中该函数会将您带到正确的 URL。
数据:
URL:(
在本示例中,我创建了一个不同的 URL,该 URL 为 http://www.n.com< /a> 对于每个结果,其中 n 是索引)
声明图表后,您可以添加一个事件侦听器,该事件侦听器将在单击某个点时触发。
这里重要的一点是
chart.getSelection()[0].row
,它告诉您这是什么结果,并获取可用于从数组中检索正确 URL 的“索引”。如果您除了在同一窗口中打开页面之外还要做其他任何事情,那么就会出现一些错误。基本上,单击同一事件两次会引发
TypeError
,这就是我将调用包装在 try catch 语句中的原因。正如我所说,可能还有另一种方法可以做到这一点,但希望这是一个好的起点。
I created a jsfiddle demo to show that it is possible to do this, but I couldn't find a way to do it in the way I would have liked.
After creating a data set, I created an array that has a list of URLs in the same order as the results that are displayed. When the select event is trigged by clicking on a point, a function is executed which in this case takes you to the correct URL.
Data:
URLs:
(in this example, I've created a different URL that will be http://www.n.com for each result, where n is the index)
Once you've declared your chart, you can then add an event listener that will trigger when a point is clicked on.
The important bit here is the
chart.getSelection()[0].row
, this tells you what result this is and gets the 'index' that you can use to retrieve the correct URL from the array.There is a bit of a bug with this if you were to anything other than open a page in the same window. Basically, clicking on the same event twice throws a
TypeError
, which is why I've wrapped the call in a try catch statement.As I said, there might be another way of doing this, but this but hopefully this a good starting point.