Javascript AmCharts 4-如何在MapPolygonSeries()中使用自定义ajax响应
我正在测试amcharts 4 map(PieChart()&MapPolygonSeries()),我有一个响应。数据如下:Javascript AmCharts 4-如何在MapPolygonSeries()中使用自定义ajax响应,javascript,arrays,amcharts,Javascript,Arrays,Amcharts,我正在测试amcharts 4 map(PieChart()&MapPolygonSeries()),我有一个响应。数据如下: { "status": 200, "legal_country": [ { "legal_country": "US", "count(*)": 171576 }, { "legal_country": "GB",
{
"status": 200,
"legal_country": [
{
"legal_country": "US",
"count(*)": 171576
},
{
"legal_country": "GB",
"count(*)": 130246
},
{
"legal_country": "DE",
"count(*)": 112459
},
{
"legal_country": "NL",
"count(*)": 96554
}
]
}
var chart = am4core.create("lei_pie", am4charts.PieChart);
chart.data = getAjaxRecords2;
var series = chart.series.push(new am4charts.PieSeries());
series.dataFields.value = "count(*)";
series.dataFields.category = "legal_country";
我将合法的国家/地区数组存储在两个变量中:
var getAjaxRecords1 = data.legal_country;
var getAjaxRecords2 = data.legal_country;
现在,对于am4charts.PieSeries(),我可以访问数据并定义如下所示的值和类别:
{
"status": 200,
"legal_country": [
{
"legal_country": "US",
"count(*)": 171576
},
{
"legal_country": "GB",
"count(*)": 130246
},
{
"legal_country": "DE",
"count(*)": 112459
},
{
"legal_country": "NL",
"count(*)": 96554
}
]
}
var chart = am4core.create("lei_pie", am4charts.PieChart);
chart.data = getAjaxRecords2;
var series = chart.series.push(new am4charts.PieSeries());
series.dataFields.value = "count(*)";
series.dataFields.category = "legal_country";
一切正常
但是如何使用MapPolygonSeries()中的数据呢?这不起作用:
// Create polygon series
var polygonSeries = chart.series.push(new am4maps.MapPolygonSeries());
polygonSeries.useGeodata = true;
...
polygonSeries.dataFields.value = "count(*)";
polygonSeries.dataFields.category = "legal_country";
polygonSeries.data = getAjaxRecords1;
。。。我在文档中找不到它:
也。因此,您可能希望提供该阵列的副本,以便原始阵列在整个应用程序中都能正常工作
在将数据传递到MapPolygonSeries
之前,您可以尝试格式化数据,例如:
var-mapData=[];
getAjaxRecords1.forEach(函数(countryData){
//使用适当的id将新对象推送到新数组中
push(Object.assign({“id”:countryData.legal_country},countryData));
});
//测试突变:
//mapData[0][“count(*)”]=5;
//getAjaxRecords1[0][“计数(*)”];//171576,不变
polygoseries.data=mapData;
但是,我不清楚您试图用这段代码做什么:
polygonSeries.dataFields.value=“count(*)”;
polygonSeries.dataFields.category=“法律\国家”;
你期望它做什么?你想通过地图系列实现什么