highcharts点击标签如何转到锚点 [英] highcharts clickable labels how to goto anchor
问题描述
我在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?
预先感谢!
另一种解决方案(不是最依赖于< text>
的跨浏览器解决方案,但可以使用不兼容的IE版本)
$(。highcharts-data-labels)。on(click,text,function(){
window.location.hash =anchor;
});
< a href =http://jsfiddle.net/jugal/ZuqGZ/ =nofollow> jsFiddle Demo
I'm using Highcharts within my Backbone application to display some information in a column graph.
I use the datalabels in the chart to allow the user to click on and move to the detail page of that datapoint. This is not a normal window.location call, but should be a window.location.hash call. This is because I want to move to an anchor, which will be picked up by my Backbone router.
This is what a typical label (using the formatter) is transformed into:
<tspan onclick="location.href="/#/test/1"" style="cursor: pointer; " x="360">Sectie nummer 6</tspan>
So in other words, is it possible to have Highcharts do a onclick="window.location.hash=..." instead of location.href?
Thanks in advance!
An alternative solution (not the most cross-browser solution because of its dependency on <text>
but you can get it working with the incompatible IE versions)
$(".highcharts-data-labels").on("click", "text", function() {
window.location.hash = "anchor";
});
这篇关于highcharts点击标签如何转到锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!