-
Notifications
You must be signed in to change notification settings - Fork 669
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
Chart forceFit为true的状态下,父组件css样式加载完后,Chart不能自适应父类组件宽度。 #75
Comments
forceFit 是监听 window resize 事件的,如果 resize 事件没有触发,那就没办法适应了。 你有没有设置 width 属性? |
Chart没有设置width属性。父组件通过element.style设置的宽度,Chart能够自动适应,但是通过css文件引入的样式,就会有问题。 我怀疑是css文件没有加载完成,绘图已经开始了,等到父组件样式加载出来后,Chart没有重绘。 初始化Chart的时机我应该控制? |
你是不是在开发模式下,生产环境没有这个问题。 |
我刚在生产环境看了,也有同样的问题。 在当前页刷新,window resize事件没有触发,canvas父类div的宽度已经改变了,但是canvas的宽度没有改变。 |
@rex11458 |
mark下,同遇到此问题,还未找到好的解决方案。 |
跟 G2 那边的人商量过了,推荐初始化时设置容器 size。 // 例如
render() {
if (this.chart) {
this.chart.forceFit();
}
return (<Chart
{...opts}
onGetG2Instance={(chart) => {
this.chart = chart;
}}
/>);
} |
试下用这个包装下 componentWillUnmount() { componentDidUpdate() { render() { |
可以在图表渲染前添加 loading,防止 data 为空时对图表进行渲染。 if (data.length === 0) {
return <div>spin</div>;
} |
狗日的,开了strictMode,缩小宽度就不会自适应 |
.ant-col-18 {
display: block;
width: 75%
The text was updated successfully, but these errors were encountered: