镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Bug] ECharts Tooltip 不显示问题 - Vue Ref vs 普通变量 #21267

Closed

Description

@trry-hub

Version

6.0.0

Link to Minimal Reproduction

https://github.com/trry-hub/issues/tree/echarts

Steps to Reproduce

复现步骤

方法一:使用普通变量(tooltip 正常工作)

let chartInstance: null | echarts.ECharts = null
const chartDom = ref()

async function renderChart() {
  if (!chartInstance) {
    chartInstance = echarts.init(chartDom.value)
  }
  chartInstance.setOption(option)
}

方法二:使用 Vue ref(tooltip 不工作)

const chartInstanceVueRef = ref()
const chartDomUseRef = ref()

async function renderChartUseRef() {
  if (!chartInstanceVueRef.value) {
    chartInstanceVueRef.value = echarts.init(chartDomUseRef.value)
  }
  chartInstanceVueRef.value.setOption(option)
}

Current Behavior

在 Vue 3 + ECharts 项目中,当使用 Vue 的 ref() 来存储 ECharts 实例时,图表的 tooltip 无法正常显示。但使用普通变量存储 ECharts 实例时,tooltip 可以正常工作。

Expected Behavior

两种方法都应该能够正常显示 tooltip,当鼠标悬停在图表上时应该显示相应的数据信息。

Environment

System:
    OS: macOS 15.6.1
    CPU: (8) arm64 Apple M1
    Memory: 94.39 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.19.0 - ~/.volta/tools/image/node/22.19.0/bin/node
    npm: 10.9.3 - ~/.volta/tools/image/node/22.19.0/bin/npm
    pnpm: 10.15.1 - ~/.volta/bin/pnpm
  Browsers:
    Chrome: 140.0.7339.133
    Safari: 18.6

Any additional comments?

可能的原因分析

  1. Vue 响应式系统干扰: Vue 的 ref 会将对象包装成响应式代理,可能影响 ECharts 内部的事件绑定机制
  2. 事件监听器绑定问题: ECharts 的 tooltip 依赖于 DOM 事件,响应式代理可能影响事件监听器的正确绑定
  3. 实例引用问题: 通过 ref 访问的 ECharts 实例可能与原始实例存在差异

临时解决方案

目前使用普通变量而非 Vue ref 来存储 ECharts 实例可以避免此问题。

Activity

  1. added
    pendingWe are not sure about whether this is a bug/new feature.
    on Sep 16, 2025
  2. echarts-bot commented on Sep 16, 2025

    @echarts-bot

    @trry-hub 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] ECharts Tooltip Not Displaying Issue - Vue Ref vs Regular Variable

    BODY

    Version6.0.0### Link to Minimal Reproductionhttps://github.com/trry-hub/issues/tree/echarts### Steps to Reproduce## Reproduction Steps### Method 1: Using regular variable (tooltip works fine)typescriptlet chartInstance: null | echarts.ECharts = nullconst chartDom = ref()async function renderChart() { if (!chartInstance) { chartInstance = echarts.init(chartDom.value) } chartInstance.setOption(option)}### Method 2: Using Vue ref (tooltip does not work)typescriptconst chartInstanceVueRef = ref()const chartDomUseRef = ref()async function renderChartUseRef() { if (!chartInstanceVueRef.value) { chartInstanceVueRef.value = echarts.init(chartDomUseRef.value) } chartInstanceVueRef.value.setOption(option)}### Current BehaviorIn Vue 3 ECharts project, when using Vue's ref() to store the ECharts instance, the chart's tooltip does not display correctly. However, when using a regular variable to store the ECharts instance, the tooltip works fine.### Expected BehaviorBoth methods should be able to display the tooltip correctly, showing the corresponding data information when hovering over the chart.### EnvironmentmarkdownSystem: OS: macOS 15.6.1 CPU: (8) arm64 Apple M1 Memory: 94.39 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.19.0 - ~/.volta/tools/image/node/22.19.0/bin/node npm: 10.9.3 - ~/.volta/tools/image/node/22.19.0/bin/npm pnpm: 10.15.1 - ~/.volta/bin/pnpm Browsers: Chrome: 140.0.7339.133 Safari: 18.6### Any additional comments?## Possible Cause Analysis1. Vue reactive system interference: Vue's ref wraps the object into a reactive proxy, which could affect ECharts' internal event binding mechanism.2. Event listener binding issue: ECharts' tooltip relies on DOM events, and the reactive proxy may interfere with the correct binding of event listeners.3. Instance reference issue: The ECharts instance accessed via ref may differ from the original instance.## Temporary SolutionCurrently, using a regular variable instead of Vue ref to store the ECharts instance can avoid this issue.

  3. Justin-ZS commented on Sep 17, 2025

    @Justin-ZS
    Contributor

    这应该是 Vue 的 bug,为什么报给 echarts ?

  4. trry-hub commented on Sep 17, 2025

    @trry-hub
    Author

    这应该是 Vue 的 bug,为什么报给 echarts ?

    我不确定具体是哪边的问题,所以两边都报了,如果不是 echarts 的问题,就关掉好了。

  5. fullmooooon commented on Sep 17, 2025

    @fullmooooon
    Contributor

    vue-echarts
    两个库不兼容也正常,为什么不用现成的 vue-echarts 呢

  6. added and removed
    pendingWe are not sure about whether this is a bug/new feature.
    on Sep 17, 2025
  7. ngd-b commented on Sep 21, 2025

    @ngd-b

    The echarts instance is a very large object, so it is not recommended to use ref. Doing so can also lead to significant performance overhead. Instead, you can use shallowRef

  8. added a commit that references this issue on Sep 26, 2025
    17b6c77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions