admin管理员组文章数量:1417538
I need to highlight mouse position when mouse is within a xAxis range of a line chart in HIighCharts. I want to display a circle to highlight the mouse position. But I want this functionality only for the last 25 xAxis values.
Is it possible to do this in Highcharts?
One way is by following code but it has its limitations:
var circle = chart.renderer.circle(0, 0, 5).attr({
fill: 'blue',
stroke: 'black',
'stroke-width': 1
}).add()
.toFront()
.hide();
$(chart.container).mousemove(function (event) {
circle.attr({
x: event.offsetX,
y: event.offsetY
});
if (event.offsetX > SOME_VALUE) circle.show();
});
The shortings are that I am paring event.offsetX instead of event.xAxis[0].value i.e. I am paring the xValue of mouse in page rather than xAxis value in chart.
Thanks in advance
I need to highlight mouse position when mouse is within a xAxis range of a line chart in HIighCharts. I want to display a circle to highlight the mouse position. But I want this functionality only for the last 25 xAxis values.
Is it possible to do this in Highcharts?
One way is by following code but it has its limitations:
var circle = chart.renderer.circle(0, 0, 5).attr({
fill: 'blue',
stroke: 'black',
'stroke-width': 1
}).add()
.toFront()
.hide();
$(chart.container).mousemove(function (event) {
circle.attr({
x: event.offsetX,
y: event.offsetY
});
if (event.offsetX > SOME_VALUE) circle.show();
});
The shortings are that I am paring event.offsetX instead of event.xAxis[0].value i.e. I am paring the xValue of mouse in page rather than xAxis value in chart.
Thanks in advance
Share Improve this question asked Mar 1, 2013 at 7:31 user1517108user1517108 2,4156 gold badges34 silver badges44 bronze badges1 Answer
Reset to default 7You can use point.plotX
and chart.plotLeft
to get position on a chart, see: http://jsfiddle/PNMAG/35/
Snippet:
function addCircle() {
var chart = this;
var circle = chart.renderer.circle(0, 0, 5).attr({
fill: 'blue',
stroke: 'black',
'stroke-width': 1
}).add()
.toFront()
.hide();
$(chart.container).mousemove(function(event) {
var normalizedEvent = chart.pointer.normalize(event);
if (normalizedEvent.chartX > chart.series[0].data[5].plotX + chart.plotLeft) {
circle.attr({
x: normalizedEvent.chartX,
y: normalizedEvent.chartY
}).show();
} else {
circle.hide();
}
});
}
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'area',
events: {
load: addCircle
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
data: [71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 20]
}]
});
本文标签: javascriptHighchartshighlight mouse position within a rangeStack Overflow
版权声明:本文标题:javascript - Highcharts - highlight mouse position within a range - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745269741a2650814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论