Comments (10)
跟 G2 那边的人商量过了,推荐初始化时设置容器 size。
同时切换页面后强制 forcetFit 。
// 例如
render() {
if (this.chart) {
this.chart.forceFit();
}
return (<Chart
{...opts}
onGetG2Instance={(chart) => {
this.chart = chart;
}}
/>);
}
from bizcharts.
试下用这个包装下
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.
forceFit 是监听 window resize 事件的,如果 resize 事件没有触发,那就没办法适应了。
可能是你初始化 chart 的时机不对,或者容器的 width 跟你的预期不一样?
你有没有设置 width 属性?
from bizcharts.
Chart没有设置width属性。父组件通过element.style设置的宽度,Chart能够自动适应,但是通过css文件引入的样式,就会有问题。 我怀疑是css文件没有加载完成,绘图已经开始了,等到父组件样式加载出来后,Chart没有重绘。 初始化Chart的时机我应该控制?
from bizcharts.
你是不是在开发模式下,生产环境没有这个问题。
from bizcharts.
我刚在生产环境看了,也有同样的问题。 在当前页刷新,window resize事件没有触发,canvas父类div的宽度已经改变了,但是canvas的宽度没有改变。
from bizcharts.
@rex11458
http://blog.csdn.net/vitohe/article/details/44590295
要不你主动触发 resize 事件。。。
from bizcharts.
mark下,同遇到此问题,还未找到好的解决方案。
from bizcharts.
from bizcharts.
可以在图表渲染前添加 loading,防止 data 为空时对图表进行渲染。
if (data.length === 0) {
return <div>spin</div>;
}
from bizcharts.
Related Issues (20)
- Tooltip报错
- legend
- react18 严格模式下, 切换 图表类型 不渲染 HOT 1
- 带有label的条形图(BizCharts@4)数据紊乱,刷新会随机出现以下2种情况,label对应的会乱
- Changing Legend onChange does not update component (temp fix found) HOT 1
- onAnnotationClick在Annotation.Html下不生效 HOT 1
- The above error occurred in the <Chart3> component: HOT 1
- English documentation
- [Feature Request]气泡散点图支持双缩略轴
- 设置了父级元素的宽高,并且把autoFit设置为true,再设置图表的宽高还是有效 HOT 1
- DonutChart的onRingClick事件该如何触发
- react 兼容版本能提升至 17.+ 吗?做个多版本兼容行吗?
- 时间类型的x轴,刻度显示的值错误
- Interval组件动态修改adjust属性视图不更新
- v4版本的Legend如何实现基于html的自定义
- Issue with Chart Visualization in React/Next.js Project Using StrictMode HOT 1
- @antv/g2 已经发布了新的大版本v5,请问是否有支持的计划?
- uglify-js:2.8.29 ,ansi-regex:2.1.1, inflight:1.0.6 ,扫描到这三个组件存在高危漏洞,请问近期有修复计划吗?
- 基础饼图的label怎么改成蜘蛛Label形式
- Scale配置中,linear类型下属性minTickInterval 设置不生效
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bizcharts.