0
我正在嘗試使用ReactJS在rect中顯示文本。我已經嘗試過允許不同的方式,但文本總是在右側的圖表的外側結束。在rect中添加文本的強制佈局圖d3.js REACTJS
我努力做到以下幾點: http://bl.ocks.org/mbostock/7341714
我得到以下結果:
我怎樣才能獲得60號出現在矩形的中間?
這裏是我的代碼:
var BarChart = React.createClass({
getInitialState: function() {
return {props: this.props};
},
componentWillReceiveProps: function(nextProps) {
this.setState({
props: nextProps
});
},
render: function() {
return (
<svg width={this.state.props.width} height={this.state.props.height}>
<g style={{strokeWidth:4, stroke:"black"}}>
<rect fill={"white"} width={146} height={18}/>
<text> {this.state.props.propValue} </text>
</g>
</svg>
);
}
我只能加酒吧內的文本,如果我取代{} this.state.props.propValue用一個非React JS變量。 如果我用簡單的字母替換它,文本將正確顯示在裏面。 – barracuda