highcharts clickable labels how to goto anchor

徘徊边缘 提交于 2019-12-20 03:09:54

问题


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=&quot;/#/test/1&quot;" 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!


回答1:


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";
});

Why jQuery.on()?

jsFiddle Demo




回答2:


window.location.hash="comment-16513878" & window.location="#comment-16513878" appear to have the same result. Have you tried that?

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

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



来源:https://stackoverflow.com/questions/12307443/highcharts-clickable-labels-how-to-goto-anchor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!