Git Product home page Git Product logo

Comments (10)

weepy3641 avatar weepy3641 commented on May 22, 2024 3

#132

跟 G2 那边的人商量过了,推荐初始化时设置容器 size。
同时切换页面后强制 forcetFit 。

// 例如
render() {
    if (this.chart) {
      this.chart.forceFit();
    }
    return (<Chart
      {...opts}
      onGetG2Instance={(chart) => {
        this.chart = chart;
      }}
    />);
  }

from bizcharts.

xxxlihui avatar xxxlihui commented on May 22, 2024 2

试下用这个包装下
class ResizeChart extends React.Component {
constructor(props) {
super(props)
}

componentWillUnmount() {
this.char = null
this.props.onUnmount && this.props.onUnmount(this.char)
}

componentDidUpdate() {
this.timeout && clearTimeout(this.timeout) && (this.timeout = null)
this.timeout = setTimeout(() => {
this.char && this.char.forceFit()
}, 300)
}

render() {
return <Chart {...this.props} onGetG2Instance={char => {
this.char = char
this.props.onGetG2Instance && this.props.onGetG2Instance(char)
}
}>
{this.props.children}

}
}

from bizcharts.

weepy3641 avatar weepy3641 commented on May 22, 2024

forceFit 是监听 window resize 事件的,如果 resize 事件没有触发,那就没办法适应了。
可能是你初始化 chart 的时机不对,或者容器的 width 跟你的预期不一样?

你有没有设置 width 属性?

from bizcharts.

rex11458 avatar rex11458 commented on May 22, 2024

Chart没有设置width属性。父组件通过element.style设置的宽度,Chart能够自动适应,但是通过css文件引入的样式,就会有问题。 我怀疑是css文件没有加载完成,绘图已经开始了,等到父组件样式加载出来后,Chart没有重绘。 初始化Chart的时机我应该控制?

from bizcharts.

OPY-bbt avatar OPY-bbt commented on May 22, 2024

你是不是在开发模式下,生产环境没有这个问题。

from bizcharts.

rex11458 avatar rex11458 commented on May 22, 2024

我刚在生产环境看了,也有同样的问题。 在当前页刷新,window resize事件没有触发,canvas父类div的宽度已经改变了,但是canvas的宽度没有改变。

from bizcharts.

weepy3641 avatar weepy3641 commented on May 22, 2024

@rex11458
http://blog.csdn.net/vitohe/article/details/44590295
要不你主动触发 resize 事件。。。

from bizcharts.

zeratul-k avatar zeratul-k commented on May 22, 2024

mark下,同遇到此问题,还未找到好的解决方案。

from bizcharts.

thetimbecker avatar thetimbecker commented on May 22, 2024

#279

from bizcharts.

gaius-qi avatar gaius-qi commented on May 22, 2024

可以在图表渲染前添加 loading,防止 data 为空时对图表进行渲染。

if (data.length === 0) {
  return <div>spin</div>;
}

from bizcharts.

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.