【问题标题】:Unable to acess API data in React-VictoryJs无法访问 React-Victory Js 中的 API 数据
【发布时间】:2021-01-29 02:41:40
【问题描述】:

由于某种原因,我无法访问 Victoryjs 图表中的 API 数据,API 工作正常,就好像我在图表之外输出数据一样,它显示了数据,但我无法让它在图表内工作。我的 API 将数据作为 JSON 对象内的 2 个数组输出。下面是我的代码,仅供参考,它不会引发任何错误。

class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
          data : [],
          dates: []
        };
    }
    componentDidMount() {
        axios
             .get("http://localhost:8000/api")
             .then(res => this.setState({data:res.data.chartdata, dates:res.data.labels}))
    }  
    render() {
      return (
        <div>
          <h1>Victory Tutorial</h1>
          <VictoryLine data={[{x:this.state.dates, y:this.state.data}]} />          
        </div>
      );
    }
}

export default Main;

【问题讨论】:

    标签: javascript reactjs victory-charts


    【解决方案1】:

    数据的 json 格式错误,我提供了 2 个单独的 JSON 数组,我需要从 API 获得一个 json 对象数组。

    【讨论】:

      猜你喜欢
      • 2023-01-09
      • 1970-01-01
      • 2021-05-04
      • 1970-01-01
      • 2018-04-18
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      相关资源
      最近更新 更多