javascript - highcharts 可点击标签如何转到 anchor

标签 javascript highcharts

我在我的 Backbone 应用程序中使用 Highcharts 在柱形图中显示一些信息。

我使用图表中的数据标签允许用户点击并移动到该数据点的详细信息页面。这不是正常的 window.location 调用,而应该是 window.location.hash 调用。这是因为我想移动到一个 anchor ,它将被我的主干路由器拾取。

这是一个典型的标签(使用格式化程序)被转换成的样子:

<tspan onclick="location.href=&quot;/#/test/1&quot;" style="cursor: pointer; " x="360">Sectie nummer 6</tspan>

换句话说,是否可以让 Highcharts 执行 onclick="window.location.hash=..."而不是 location.href?

提前致谢!

最佳答案

替代解决方案(不是最跨浏览器的解决方案,因为它依赖于 <text>,但您可以使用不兼容的 IE 版本)

$(".highcharts-data-labels").on("click", "text", function() {
    window.location.hash = "anchor";
});

Why jQuery.on() ?

jsFiddle Demo

关于javascript - highcharts 可点击标签如何转到 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12307443/

相关文章:

javascript - 将特殊字符组合到数组中的前一个索引

javascript - 如何在动态图中使用 highcharts 应用渐变。

javascript - 不同图表之间的视觉差异

javascript - Visual Studio Code Intellisense 不适用于 Javascript

javascript - 带数组的一键多项功能

javascript - 如何使键码适用于西里尔字母

javascript - 如何使图像在仪表中居中

javascript - 将数据放在指定日期的 highcharts 中

javascript - 第二个弹出窗口表示 Highchart 不适用于传单 geojson 多边形

javascript - 如何在react js中实现DIAL协议(protocol)?