首页 > 解决方案 > 从 api 获取值并显示在 reactjs 应用饼图中

问题描述

我从返回值的地方创建了 API,现在我试图获取这些值并使用 reactjs 在饼图中显示,但无法获取。


class Graph extends Component {
    ComponentWillMount(){
        fetch('http://localhost:3010/analysis')
        .then(response{response.json()})
        .then(data => console.log(response))
    }
    render() {
        return (
            <ReactFC
        {...pieConfigs}/>
            );
    }
}

export default Graph;

这是我的代码。谁能告诉我为了能够在 React 应用程序中显示饼图需要进行哪些更改?

标签: python-3.xreactjsapi

解决方案


问题是您在组件卸载后立即获取 API,尝试

ComponentDidMount(){
    fetch('http://localhost:3010/analysis')
    .then(response{response.json()})
    .then(data => console.log(response))
}

推荐阅读