【发布时间】:2020-03-11 12:01:14
【问题描述】:
我从 API 接收到这样的数据
{
"Bob Knight": 30774.72000002,
"Samuel Herman": 10310.61000004,
"Lucie Perry": 26308.41,
"Andreas Smith": 8960.189999999999,
"Frederic Smith": 2029.5000000599998,
}
我正在尝试在我的反应应用程序中使用顶点图表在条形图中显示它,但是我似乎无法以正确的方式格式化数据以使顶点显示任何内容。我尝试过像这样在javascript中格式化:
{
{x: "Bob Knight", y:"30774.720002"},
...
}
这似乎是文档建议的内容,但它没有呈现任何内容。以下是我的组件的有用部分
constructor(props) {
super(props);
this.state = {
options: {
chart: {
id: "basic-bar"
},
xaxis: {
type: 'category'
}
},
values: []
}
}
componentDidUpdate(prevProps) {
if (!equal(this.props.selectedDate, prevProps.selectedDate))
{
var m = moment(this.props.selectedDate).format("M");
var y = moment(this.props.selectedDate).format("YYYY");
axios.get('http://localhost:8080/opportunity/owner/' + y + '/' + m)
.then(res => {
values = res.data;
this.setState({
values
})
})
.catch(console.log)
}
}
render(
<Chart series = {this.state.values} type ='bar' options ={this.state.options}/>
【问题讨论】:
标签: javascript reactjs apexcharts