Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Vue3 support seems not to behave correctly #17723

Closed
Tails128 opened this issue Oct 4, 2022 · 7 comments
Closed

[Bug] Vue3 support seems not to behave correctly #17723

Tails128 opened this issue Oct 4, 2022 · 7 comments
Assignees
Labels
en This issue is in English FAQ Frequent Asked Questions not-a-bug third-party

Comments

@Tails128
Copy link

Tails128 commented Oct 4, 2022

Version

5.4.*

Link to Minimal Reproduction

https://github.com/Tails128/echart-vue-issue

Steps to Reproduce

Please refer to the github repo for how the chart was created & what the option is.

In order to see the error (you will see it in the console), just resize the window.

I am afraid I'm setting it up incorrectly, if so please add a guide on how to setup echart for vue3

Current Behavior

  • Errors are triggered on resize
  • The resize doesn't happen
  • The labels sometimes don't work (not available in the example)

Expected Behavior

  • Resize should be possible

Environment

- OS: macOS Monterey
- Browser: Chrome 96.0.4664.55
- Framework Vue@3

Any additional comments?

No response

@Tails128 Tails128 added the bug label Oct 4, 2022
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Oct 4, 2022
@plainheart
Copy link
Member

Please search related issues with the keyword “vue” and you might find the answer. :)

@plainheart plainheart added third-party not-a-bug and removed bug pending We are not sure about whether this is a bug/new feature. labels Oct 5, 2022
@Tails128
Copy link
Author

Tails128 commented Oct 5, 2022

@plainheart
Could you point me out to something? I can't seem to find much...

It still seems a bug to me given it's not behaving as expected and there's no explaination on what is going wrong...
I mean, if i see no error I don't understand why I get no label, why it doesn't resize and so on...

@YuShengHou
Copy link
Contributor

YuShengHou commented Oct 5, 2022

@Tails128
The following code should solve your problem. It is not a good practice to use the return value of echarts.init as a reactive value. you have a high probability of being wrong because of that.

<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import * as echarts from "echarts";
import { useWindowSize } from "@vueuse/core";
const option = {
  xAxis: {
    type: "category",
    data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  },
  yAxis: {
    type: "value",
  },
  series: [
    {
      data: [150, 230, 224, 218, 135, 147, 260],
      type: "line",
    },
  ],
};

const graphRef = ref()
let chart = null as unknown as echarts.ECharts

onMounted(() => {
  chart = echarts.init(graphRef.value);
  chart.setOption(option);

  const { width } = useWindowSize();
  watch(width, () => {
    if (chart != undefined) {
      console.log("Trying to resize!");

      chart.resize({
        width: width.value,
        height: 300
      });
      console.log(width.value)
    }
  });
})
</script>

<template>
  <div style="
      width: 100vw;
      height: 100vh;
      display: flex;
      align-items: center;
      justify-items: center;
    ">
    <div id="graph" ref="graphRef" style="width: 100%; height: 300px" />
  </div>
</template>

<style>
body,
html {
  margin: 0;
  padding: 0;
}
</style>

@plainheart
Copy link
Member

We've answered many similar issues brought by vue. I believe you may find useful information from the search result if you'd like. But I think it needs to be reiterated that the instance of echarts shouldn't be made reactive as it may affect the access to the properties of inner models and bring some unexpected issues. It's good and suggested to use a normal variable or any shallow API (like shallowRef, shallowReactive) or use markRaw to prevent the instance object from being converted to a proxy.

See also the tips from the documentation of Vue.js.

  • Some values simply should not be made reactive, for example a complex 3rd party class instance, or a Vue component object.
  • Skipping proxy conversion can provide performance improvements when rendering large lists with immutable data sources.

In the end, there is a list of partial related issues.

@YuShengHou

This comment was marked as off-topic.

@plainheart plainheart added the FAQ Frequent Asked Questions label Oct 5, 2022
@Tails128
Copy link
Author

Tails128 commented Oct 5, 2022

I see... do you think it would be possible to include this in the "get started" section or in any documentation?

While it's true there are closed issues already, it's not super simple to find them and a simple warning text could save devs a lot of time and it could also save the project a lot of duplicated bugs

@plainheart
Copy link
Member

Thanks for your suggestion. Though it's possible to mention this issue in the handbook or the FAQ page, I think it is mainly due to the third-party 'vue' and this is not a bug of ECharts. We need to read the documentation carefully and notice the warnings about the usage when using a third-party library. It's always good to report a bug without any external framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
en This issue is in English FAQ Frequent Asked Questions not-a-bug third-party
Projects
None yet
Development

No branches or pull requests

3 participants