gpt4 book ai didi

javascript - 使用循环在饼图上发送值

转载 作者:行者123 更新时间:2023-11-30 14:54:49 25 4
gpt4 key购买 nike

我正在尝试获取名为“pie”的饼图循环数组的数据。但是在选定的行 e.location 出现错误。我有评论那行。这是图片。请帮我找到解决方案image where i get the error

<div class="col-md-6">
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>

<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/pie.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>

<script>
var pie = [
{"id":"1","location":"address1","value":"20"},
{"id":"2","location":"address2","value":"30"},
{"id":"3","location":"address3","value":"40"},
{"id":"4","location":"address4","value":"50"},
{"id":"5","location":"address5","value":"60"},
{"id":"6","location":"address6","value":"70"},
{"id":"7","location":"address7","value":"80"},
];

console.log(pie);

pie.map((e) => {
console.log(e.location);
return e;
});

var chart = AmCharts.makeChart( "chartdiv", {
"type": "pie",
"theme": "light",
"dataProvider": [pie.map((e)=>{
"location": e.location, //here is the error
"value": e.value //here is the error
})],
"valueField": "value",
"titleField": "location",
"balloon":{
"fixedPosition":true
},
"export": {
"enabled": true
}
});
</script>

<div id="chartdiv"></div>
</div>

最佳答案

看起来你根本不需要做那个映射,没有它它也能工作。

所以只需使用"dataProvider": pie,

Here's a working version on JSFiddle.

关于javascript - 使用循环在饼图上发送值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47471145/

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