我正在尝试制作我使用的一些数据的直方图react-d3-components
。我的代码是这样的
import React, { Component } from 'react';
import * as d3 from 'd3';
import * as ReactD3 from 'react-d3-components';
import propTypes from 'prop-types';
var axios=require('axios');
var BarChart=ReactD3.BarChart;
class App extends Component {
constructor(props){
super(props);
this.state={
data:[],
label:'',
values:[],
x:'',
y:''
}
}
componentDidMount(){
this.loadData();
}
loadData(){
var me=this;
axios({
method:'GET',
url:'https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=SPY&apikey=2QEL3WC4KITIBISR',
}).then(function(response){
var values=[];
var data=[];
Object.keys(response.data['Monthly Time Series']).forEach(function(k){
var y=response.data['Monthly Time Series'][k]["1. open"];
me.setState({
label:k,
x:k,
y:y
})
})
values.push({"x":me.state.x,"y":me.state.y});
data.push({"label":me.state.x,"values":values});
me.setState({
data:data
})
console.log(me.state.data);
}).catch(function(error){
console.log(error);
})
}
render() {
return (
<div>
<BarChart data={this.state.data} width={100} height={100}/>
</div>
)
}
}
App.propTypes={
values:React.PropTypes.array
}
export default App;
我指的文档是这个
c 中 data 的值onsole.log(me.state.data)
是这个 [{…}]
0
:
label
:
"2000-02-29"
values
:
Array(1)
0
:
{x: "2000-02-29", y: "139.8000"}
length
:
1
__proto__
:
Array(0)
__proto__
:
Object
length
:
1
__proto__
:
Array(0)