Code Monkey home page Code Monkey logo

Comments (4)

pearmini avatar pearmini commented on May 20, 2024 1

autoFit 不会去监听容器变化事件,如果希望图表跟随容器,可以自己监听容器变化事件,然后调用 chart.forceFit()

from g2.

hustcc avatar hustcc commented on May 20, 2024

因为 G2 监听的是 window resize 事件,所以修改容器样式之后,手动出发一个 window resize 事件也可以实现。

from g2.

YY88Xu avatar YY88Xu commented on May 20, 2024

@pearmini @hustcc 监听的是 window resize 事件有问题,就是容器的宽度是按照百分比给的比如 60%,当用户直接调整浏览器页面大小会触发 resize 没有问题。但是在微前端环境下,左侧菜单有可能会收起来,那么这个时候只是容器改变了大小,图表不会forceFit。
如果设置 autoFit 为 true,自己监听容器大小变化,调用 chart.forceFit() 会进入死循环,页面一直会调用监听容器的函数。手动出发一个 window resize 事件,也是会死循环。

如果监听直接监听容器的大小,自己实现autoFit 为 false。new Chart({ container: eeChartRef.value, autoFit: false }) 怎么给 width 和 height 呢?因为 width 和 height 不支持 100% 这种设置。

from g2.

hustcc avatar hustcc commented on May 20, 2024
  1. 关闭 autoFit
  2. 监听容器大小变化,或者容器宽高,可以使用 size-sensor 库
  3. 容器变化的时候,调用 chart.changeSize 方法

from g2.

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.