最近我尝试使用谷歌图表。在后端,我使用python&;数据库postgres。对于绑定数据,我编写了一个RESTAPI。并称之为我的前端(react)
getLeadSourceList = () => {
axios.get( this.state.apiUrl+'/api/v1/SalesLead/getLeadsByLeadSource', {})
.then((response) => {
console.log("response",response.data.data);
this.setState({ leadSourceList: response.data.data });
}).catch((error)=>{ console.log("error",error); this.setState({ leadSourceList: [] }); });
};
render() {
const pieData = this.state.leadSourceList.map((lead, key) => {
return <p>{lead.lead_source},
{lead.count}</p>
})
}
价值来自:
PBazar 9
Rashed 3
websource 4
Messenger 2
Fahme bhai 2
但是google chart期望这种类型的价值:
data={[
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
]}
图表代码的其余部分:
<Chart
width={'500px'}
height={'300px'}
chartType="PieChart"
loader={<div>Loading Chart</div>}
data={[
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
]}
options={{
title: 'My Daily Activities',
}}
rootProps={{ 'data-testid': '1' }}
/>
所以我的问题是如何绑定谷歌图表所期望的数据?提前谢谢
目前没有回答
相关问题 更多 >
编程相关推荐