我有以下图表:
const quotesChart = echarts.init(quotesContainer);
quotesChart.setOption({
dataset: [
{ source: quotes }
],
xAxis: [
{
type: 'category',
},
],
yAxis: [
{
position: 'left',
}
],
series: [
{
name: 'Quotes',
type: 'line',
datasetIndex: 0,
}
]
})
quotesChart.getZr().on("mousemove", function(params){
const pointInPixel = [params.offsetX, params.offsetY];
// how do I get x and y values for current mouse position?
// I see some examples using convertFromPixel but I don't know how to use these coordinates to get x and y values
const pointInGrid = quotesChart.convertFromPixel('grid', pointInPixel);
})
quotes
数据集源如下所示:[{period: '20/01/2021', value: 15.59}, {period: '21/01/2021', value: 15.99}]
我需要从 x 轴和 y 轴获取值(例如:
20/01/2021
和15.59
),但我不知道如何,我只有网格坐标。
谢谢。
比我想象的要简单,原来
pointInGrid[0]
是系列数组的位置,所以我做了:quotes[pointInGrid[0]]
来获取我需要的系列项目。
令 x = pointInGrid[0];
让 y = pointInGrid[1];