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