我有这个系列:
var series = chart.series.push(
am5xy.SmoothedXLineSeries.new(am5root, {
xAxis: xAxis,
yAxis: yAxis,
valueYField: "height",
valueXField: "number",
interactive: true,
interactiveChildren: true,
tooltip: am5.Tooltip.new(am5root, {
labelText:"{valueX}, {valueY}",
pointerOrientation:"horizontal"
})
})
);
还有这个活动:
series.events.on("pointerover", function(ev) {
let xPosition = ev.point.x;
let yPosition = ev.point.y;
});
但是变量 xPosition 和 yPosition 包含光标的坐标,而不是图形上点的坐标。如何获取图表上某个点的坐标?
series.events.on("pointerover", function(ev) {
let xPosition = ev.point.x;
let yPosition = ev.point.y;
});
我通过这种方式得到了我需要的结果:
series.events.on("globalpointermove", function(ev) {
if(typeof ev.target.getTooltip() === 'undefined' || typeof ev.target.getTooltip().dataItem==='undefined' || typeof ev.target.getTooltip().dataItem.dataContext === 'undefined') { return; }
else {
if(activeCharts){
let point = ev.target.getTooltip().dataItem.dataContext;
}
}
});