我无法复制这种MapImageSeries
通过其addData
方法将数据动态添加到 a需要刷新图表的行为(对于它的价值,用户将相同的问题发布到我们的 GitHub并在那里解决了它。)。imageSeries.addData(...)
应该可以正常工作。
设置代码:
// Create map instance
var chart = am4core.create("chartdiv", am4maps.MapChart);
// Set map definition
chart.geodata = am4geodata_worldLow;
// Create map polygon series
var polygonSeries = chart.series.push(new am4maps.MapPolygonSeries());
// Make map load polygon (like country names) data from GeoJSON
polygonSeries.useGeodata = true;
// Create image series
var imageSeries = chart.series.push(new am4maps.MapImageSeries());
// Create a circle image in image series template so it gets replicated to all new images
var imageSeriesTemplate = imageSeries.mapImages.template;
var circle = imageSeriesTemplate.createChild(am4core.Circle);
circle.radius = 4;
circle.fill = am4core.color("#B27799");
circle.stroke = am4core.color("#FFFFFF");
circle.strokeWidth = 2;
circle.nonScaling = true;
circle.tooltipText = "{title}";
// Set property fields
imageSeriesTemplate.propertyFields.latitude = "latitude";
imageSeriesTemplate.propertyFields.longitude = "longitude";
测试代码(addPlace
方法):
// Add data for the three cities
var data = [{
"latitude": 48.856614,
"longitude": 2.352222,
"title": "Paris",
zoomLevel: 1
}, {
"latitude": 40.712775,
"longitude": -74.005973,
"title": "New York",
zoomLevel: 2
}, {
"latitude": 49.282729,
"longitude": -123.120738,
"title": "Vancouver",
zoomLevel: 4
}];
const dataIterator = data[Symbol.iterator]();
function addPlace() {
var item = dataIterator.next();
if ( !item.done) {
imageSeries.addData(item.value);
}
}
这是一个快速演示:
https://codepen.io/team/amcharts/pen/c5a5803d81b9517a8fd37d4e2c6541ed
“添加标记”按钮每次添加一个标记(最多 3 次,因为数组中只有 3 个项目),而无需刷新图表(通过invalidate
或其他方式)。