【发布时间】:2020-04-29 20:55:03
【问题描述】:
我有一个这样的 JSON 数据: My JSON data
这是我的代码:
class WorldLineChart extends Component{
constructor(props) {
super(props);
this.state = {
data: []
};
}
componentDidMount(){
axios.get(`https://td.fpt.ai/corona/corona-total.json`)
.then(res => {
const data = res.data;
console.log(data);
this.setState({data: data});
});
}
render(){
const data = this.state
return(
<div>
</div>
)
}
}
我想知道如何获取所有键和每个值(这是一个数组)来使用 ReactJs 绘制折线图。
这是我的折线图的代码:
const lineChart = (
data
? (
<Line
data = {{
labels: //what i have to put in here,
datasets: [{
data: //what i have to put in here,
label: 'Infected',
borderColor: '#3333ff',
fill: true
}, {
data: //what i have to put in here,
label: 'Recovered',
borderColor: 'green',
backgroundColor: 'rgba(255,0,0,0.5)',
fill: true
},{
data: //what i have to put in here,
label: 'Deaths',
borderColor: 'red',
backgroundColor: 'rgba(0, 255, 0, 0.5)',
fill: true
}],
}}
/> ): null
);
非常感谢!
【问题讨论】: