2

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

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

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

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

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

提前致谢!

4

2 回答 2

0

window.location.hash="comment-16513878"&window.location="#comment-16513878"似乎有相同的结果。你试过吗?

formatter: function() {
    return '<a href="#somePlaceHolder" >' + this.y + '</a>';
}

http://jsfiddle.net/jugal/BUxMZ/

于 2012-09-06T20:33:40.093 回答
0

另一种解决方案(不是最跨浏览器的解决方案,因为它依赖于<text>但你可以让它与不兼容的 IE 版本一起使用)

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

为什么jQuery.on()

jsFiddle 演示

于 2012-09-08T09:20:01.773 回答