나는 내 상태로 데이터를 가져 와서 config 변수에서 데이터의 일부를 사용하려고하므로이 데이터를 highChart에 렌더링 할 수 있습니다. 그러나, "내 'json 호출에서 다른 데이터에 대한 정의되지 않은'SeriesDates '등의 속성을 읽을 수 없다는 오류가 계속 발생합니다. 그러나 콘솔에 상태를 기록하면 데이터가 명확하게 상태에 있습니다. config 변수에서 사용할 수 없으며 어떻게 변수 값으로 가져올 수 있습니까? 내 redux 상태 ({this.props.stock.Name})에서 데이터를 사용할 수 있지만 동일하지 않습니다. 내 JSON 호출의 출력.변수 내에서 상기 데이터를 사용하려고 할 때 구성 요소 내에서 json 데이터를 사용할 수 없습니다.
import React, { Component } from 'react';
import { connect } from 'react-redux';
import ReactHighcharts from 'react-highcharts';
class StockChart extends Component {
constructor(props) {
super(props);
this.state = {chart: []};
}
componentDidMount() {
this.ChartData();
}
ChartData() {
return $.getJSON(`http://dev.markitondemand.com/MODApis/Api/Timeseries/json?symbol=${this.props.stock.Symbol}`)
.then((data) => {
var raw = JSON.stringify(data);
var json = JSON.parse(raw);
this.setState({ chart: json });
console.log(this.state);
});
}
render() {
const config = {
title: {
text: `${this.props.stock.Name}`,
x: -20 //center
},
subtitle: {
text: `${this.props.stock.Symbol}`,
x: -20
},
xAxis: {
categories: `${this.state.chart.Data.SeriesDates}`
},
yAxis: {
title: {
text: 'Price'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '$'
},
series: [{
name: 'AAPL',
data: `${this.state.chart.Data.close.values}`
}]
};
if (!this.props.stock) {
return <div></div>
}
return (
<div>
<ReactHighcharts config={config}></ReactHighcharts>
</div>
);
}
}
function mapStateToProps(state) {
return {
stock: state.selectedStock
};
}
이미 Redux를 사용하고 있으므로 차트 데이터를 전체 Redux 상태로 옮길 것이므로 구성 요소는 데이터를 가져 오는 방법과 관련이 없습니다. –