0

我的应用场景: 我想通过点击数据点来获取被点击的点数据和其他属性,然后通过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);
})

期待您的回复

4

1 回答 1

1

要在鼠标单击时获取数据点,您可以在系列上注册 onmouseclick 事件并调用solveNearestFromScreen 方法来获取数据点。传递给solveNearestFromScreen的参数应该是翻译成引擎位置的鼠标光标位置,例如你可以参考下面的代码: -

//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 ) ) )

    } )
    
于 2020-08-31T12:55:49.433 回答