Giter VIP home page Giter VIP logo

Comments (4)

alexey-yarmosh avatar alexey-yarmosh commented on May 30, 2024

Ok, after some searching on other github repos solution seems to be:

const [chartInstance, setChartInstance] = useState<EChartsType | null>(null);
  const skiaRef = useRef(null);

  useEffect(() => {
    let chart: EChartsType | null = null;
    if (skiaRef.current && !chartInstance) {
      chart = echarts.init(skiaRef.current, 'light', {
        renderer: 'svg',
        width: E_WIDTH,
        height: E_HEIGHT,
      });
      chart.setOption(options);
      setChartInstance(chart);
      return () => chart?.dispose();
    }
  }, []);

  useEffect(() => {
    chartInstance?.setOption(options);
  }, [data]);

Hope that is correct implementation. Original link: https://github.com/windalfin/fasttt/blob/ff30b40a040700e5fc99f807fa96cda3951ca01d/src/components/HomePage/FastingProgressGauge.tsx#L86-L105

from react-native-echarts.

yechunxi avatar yechunxi commented on May 30, 2024

Ok, after some searching on other github repos solution seems to be:

const [chartInstance, setChartInstance] = useState<EChartsType | null>(null);
  const skiaRef = useRef(null);

  useEffect(() => {
    let chart: EChartsType | null = null;
    if (skiaRef.current && !chartInstance) {
      chart = echarts.init(skiaRef.current, 'light', {
        renderer: 'svg',
        width: E_WIDTH,
        height: E_HEIGHT,
      });
      chart.setOption(options);
      setChartInstance(chart);
      return () => chart?.dispose();
    }
  }, []);

  useEffect(() => {
    chartInstance?.setOption(options);
  }, [data]);

Hope that is correct implementation. Original link: https://github.com/windalfin/fasttt/blob/ff30b40a040700e5fc99f807fa96cda3951ca01d/src/components/HomePage/FastingProgressGauge.tsx#L86-L105

@alexey-yarmosh Did this approach solve your problem? This is the correct implementation. When options change, instead of re-creating the echart instance, directly call setOption to re-render the chart.

However, some users still find that page switching is too fast and errors occasionally occur. After the echart instance is destroyed, some internal operations may continue to cause errors. like this discussion. We also submitted a PR to zrender to solve the change problem, but the PR is still waiting for official verification and merging.

from react-native-echarts.

alexey-yarmosh avatar alexey-yarmosh commented on May 30, 2024

Yes, seems to be working for now. If some issues arise I'll get back here.
Also probably that usage worth documenting on the website, I can assist with that if needed.

from react-native-echarts.

yechunxi avatar yechunxi commented on May 30, 2024

Yes, seems to be working for now. If some issues arise I'll get back here. Also probably that usage worth documenting on the website, I can assist with that if needed.

Thank you for your suggestion. Welcome to submit a PR to write the document. This way you can provide more examples.
This issue will be closed. If you have other questions, welcome to open a new issue.

from react-native-echarts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.