You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportclassAppextendsReact.Component{state={g: null,}onRef=(ref)=>{this.setState({g: d3.select(ref)},()=>this.renderBubbles(this.props.data))}renderBubbles(data){constbubbles=this.state.g.selectAll('.bubble').data(data,d=>d.id)// Exitbubbles.exit().remove()// EnterconstbubblesE=bubbles.enter().append('circle').classed('bubble',true).attr('r',0).attr('cx',d=>d.x).attr('cy',d=>d.y)// Update// ...// can use animations like this nowbubblesE.transition().duration(2000).attr('r',d=>d.radius)}componentWillReceiveProps(nextProps){// we have to handle the DOM ourselves nowif(nextProps.data!==this.props.data){this.renderBubbles(nextProps.data)}}shouldComponentUpdate(){returnfalse}render(){const{ width, height }=this.propsreturn(<svgwidth={width}height={height}><gref={this.onRef}className="bubbles"/></svg>)}}
D3 与 React
React render D3 图表
d3.transition
D3 render 图表
D3 与 React 融合
React 渲染 (大部分)静态的组件(Container 、Title 、 Axis 、 Legend)
D3 渲染需要动效也就是数据部分(Data Series)
参考
How to use D3.js in React | cmichel
The text was updated successfully, but these errors were encountered: