0
我正在尝试使用React + D3创建气泡图时遇到问题。 我知道这个解决方案有npm模块,但是我不能将它们应用到我正在工作的项目中,并且缺乏使用新的React,ES6的方法来构建此图表的示例,这有点痛苦。 所以,我能够建立一个正常的图表下面这个article:使用Reactjs和D3创建气泡图
// Dependencies.
import React, { Component } from 'react';
import '../App.css';
import { scaleLinear } from 'd3-scale';
import { max } from 'd3-array';
import { select } from 'd3-selection';
import * as d3 from "d3";
class FeatureFour extends Component{
constructor(props) {
super(props);
this.state = {
data : this.props.data
};
this.createBarChart = this.createBarChart.bind(this)
};
componentDidMount() {
this.createBarChart();
}
componentDidUpdate() {
this.createBarChart()
}
createBarChart() {
const node = this.node;
const advImpact = this.state.data;
const color = "blue";
const dataMax = max(advImpact);
console.log(dataMax);
const yScale = scaleLinear()
.domain([0, dataMax])
.range([0, this.props.size[1]])
select(node)
.selectAll('rect')
.data(advImpact)
.enter()
.append('rect')
select(node)
.selectAll('rect')
.data(advImpact)
.exit()
.remove()
select(node)
.selectAll('rect')
.data(advImpact)
.style('fill', '#fe9922')
.attr('x', (d,i) => i * 25)
.attr('y', d => this.props.size[1] - yScale(d))
.attr('height', d => yScale(d))
.attr('width', 25);
};
render() {
return (
<div>
<svg ref={node => this.node = node} width={500} height={500}>
</svg>
</div>
)
}
}
// Component.
export default FeatureFour;
所以我的问题是...到变换分析这张图并追加了一圈,并创造了radious
验证码被调用,如:
<FeatureFour data={[5,10,1,3]} size={[500,500]}/>
,但数据是一个JSON
{
"children": [
{ "id": 1,
"title": "oneField",
"size": 150,
"g": 80
},
{ "id": 2,
"title": "Teaser",
"size": 30,
"g": 50
},
{ "id": 3,
"title": "Crazy",
"size": 70,
"g": 80
}
]
}
如果尺寸将决定radious和Yaxis,g将是Xaxis
谢谢。