如何在AmCharts 5中将鼠标悬停在图表上时获取点的坐标?

问题描述 投票:0回答:1

我有这个系列:

 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;
          
        
    });
amcharts amcharts5
1个回答
0
投票

我通过这种方式得到了我需要的结果:

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;
            
        }
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.