echarts [Bug] convertFromPixel后的索引不准,且出现小数

kfgdxczn  于 2022-12-31  发布在  Echarts
关注(0)|答案(3)|浏览(608)

Version

5.2.2

No response

Steps to Reproduce

chart.getZr().on('click', (params) => {

const pointInPixel = [params.offsetX, params.offsetY];

  const yIndex = chart.convertFromPixel(
   {
      seriesIndex: 0
    },
    pointInPixel
  )[1];
  const yData = options.yAxis.data[yIndex];
  console.log(yIndex, options);
});

Current Behavior

yIndex 打印出来是小数,并不是索引

Expected Behavior

期望 yIndex 打印出来是索引值

Environment

- OS:
- Browser:chrome
- Framework:

Any additional comments?

No response

cmssoen2

cmssoen21#

@snowyang2021 It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗
TRANSLATED

TITLE

[Bug] The index after convertfromPixel is inaccurate and decimal

BODY

Version

5.2.2

No response

Steps to Reproduce

chart.getZr().on('click', (params) => {

const pointInPixel = [params.offsetX, params.offsetY];

  const yIndex = chart.convertFromPixel(
   {
      seriesIndex: 0
    },
    pointInPixel
  )[1];
  const yData = options.yAxis.data[yIndex];
  console.log(yIndex, options);
});

Current Behavior

yIndex is printed as a decimal, not an index

Expected Behavior

Expect yIndex to print out the index value

Environment

- OS:
- Browser:chrome
- Framework:

Any additional comments?

No response

a7qyws3x

a7qyws3x2#

converFromPixel 返回的是数据并不是索引,是否是小数取决于 y 轴数据类型

q3qa4bjr

q3qa4bjr3#

我看官方文档上写的叫刻度值。“[300, 900] 表示该点 x 轴上对应刻度值 300,y 轴上对应刻度值 900”。刻度值是什么意思?如果yAxis是category类型的,那刻度值怎么和索引值对应上呢? https://echarts.apache.org/examples/zh/editor.html?c=bar-rich-text

相关问题