问题描述
我的应用场景: 我想通过点击数据点来获取点击点数据和其他属性, 然后通过PrimaryKey或其他属性获取其他数据。 用于显示在其他图表上。 我目前遇到的问题是: Lineseries的“ onMouseClick”事件返回的参数,我找不到点击点的数据和其他属性; 我尝试了两种方法,但是找不到点击点的数据。
[1]:
lineseries.onMouseClick(function(serie,event) {
let point = serie.solveNearestFromScreen({
x: event.screenX,y: event.screenY
});
console.log(point)
})
[2]:
lineseries.onMouseClick(function(serie,event) {
console.log('serie',serie);
console.log('event',event);
})
希望收到您的来信
解决方法
要通过鼠标单击获取数据点,您可以在系列上注册onmouseclick事件,然后调用resolveNearestFromScreen方法获取数据点。传递给resolveNearestFromScreen的参数应该是转换为引擎位置的鼠标光标位置的位置,例如,您可以参考以下代码:-
//attaching an on click event to the seires
series.onMouseClick( ( series,event ) => {
//convert client location to engine canvas location
const engineLocation = chart.engine.clientLocation2Engine( event.clientX,event.clientY )
//fetching the data point and other parameters. The location parameter gives the data point
console.log( series.solveNearestFromScreen( chart.engine.clientLocation2Engine( event.clientX,event.clientY ) ) )
} )