Wil*_*son 5 javascript reactjs apexcharts
我从 API 接收这样的数据
{
"Bob Knight": 30774.72000002,
"Samuel Herman": 10310.61000004,
"Lucie Perry": 26308.41,
"Andreas Smith": 8960.189999999999,
"Frederic Smith": 2029.5000000599998,
}
Run Code Online (Sandbox Code Playgroud)
我试图在我的 React 应用程序中使用顶点图表在条形图中显示它,但是我似乎无法以正确的方式格式化数据以使顶点显示任何内容。我试过在 javascript 中这样格式化:
{
{x: "Bob Knight", y:"30774.720002"},
...
}
Run Code Online (Sandbox Code Playgroud)
这似乎是文档建议的内容,但它没有呈现任何内容。以下是我的组件的有用部分
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}/>
Run Code Online (Sandbox Code Playgroud)
const obj = {
"Bob Knight": 30774.72000002,
"Samuel Herman": 10310.61000004,
"Lucie Perry": 26308.41,
"Andreas Smith": 8960.189999999999,
"Frederic Smith": 2029.5000000599998,
}
const arr = Object.entries(obj).map(x => ({
'x': x[0],
'y': x[1]
}))
console.log(arr)Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
504 次 |
| 最近记录: |