gpt4 book ai didi

javascript - 如何修改 JSON 标签 React JS

转载 作者:行者123 更新时间:2023-11-29 23:21:14 27 4
gpt4 key购买 nike

我正在尝试在 ReactJS 页面中添加图表。在同一页中,我在表格中获取了数据,我希望这些数据与我的图表相同。我的图表是这样的:

export const myDataSourcePie ={
chart: {
caption: "Title",
subcaption: "Friends' chart",
startingangle: "120",
showlabels: "0",
showlegend: "1",
enablemultislicing: "0",
slicingdistance: "15",
showpercentvalues: "1",
showpercentintooltip: "0",
plottooltext: "Friend's email : $label Total messages : $datavalue",
theme: "ocean"
},
data: [
{
label: 'email',
value: '17',
},
{
label: 'email',
value: '100',
},
{
label: 'email',
value: '17',
},
{
label: 'email',
value: '17',
},
{
label: 'email',
value: '17',
},
{
label: 'email',
value: '17',
},
{
label: 'email',
value: '100',
},
{
label: 'email',
value: '17',
},
]
}

export const chartConfigs = {
type: 'pie3d',
width: 800,
height: 600,
dataFormat: 'json',
dataSource: myDataSourcePie
};

然后我导入它然后用

渲染它
<ReactFC {...chartConfigs} />

现在显然我的 JSON 中的数据不是正确的数据。我有一个“ friend ”对象列表

    friends:[
{"first_name": "name",
"surname": "surname",
"email": "foo@foo.com",
"date_of_birth": "1982-02-20",
"nationality": "Japan",
"messages": 5
},
{...},
{...},
..
]

我从中获取要放入表中的数据,我只想获取此对象列表的两个标签以放入图表中(电子邮件和消息)。我怎么能把这个值放在我的“myDataSourcePie”中?带 Prop ?谢谢

最佳答案

试试这个:

getFriendsChart()
{
let dataChart = [];

this.state.friends.forEach( function( friend ) {

dataChart.push(
{
label: friend.email,
value: friend.messages,
}
);
});

let tempConfig = {...chartConfigs};
tempConfig.dataSource.data = dataChart;

return tempConfig;
}

关于javascript - 如何修改 JSON 标签 React JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50552320/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com