amCharts V4 地图中的 clickMapObject 方法
clickMapObject method in amCharts V4 maps
我需要帮助找到一种方法来在 v4 中从 amcharts v3 复制以下功能但没有成功:
在 V3 中:map.clickMapObject(map.getObjectById('CA'));
在 V4 中:chart.METHOD???(polygonSeries.getPolygonById("CA"))
我在这里想要实现的是通过单击地图外的元素打开区域模式。
谢谢
在 v4 中,您可以在 polygonSeries.mapPolygons.template
上分配一个 hit
事件 (our Events guide),例如:
// Open modal on click
polygonTemplate.events.on("hit", function(event) {
// chart.closeAllPopups(); // <-- if using an amCharts Popup
chart.openModal(
"The id for " +
event.target.dataItem.dataContext.name +
" is <strong>" +
event.target.dataItem.dataContext.id +
"</strong>."
);
// if using an amCharts popup, replace openModal with openPopup
});
不确定区域模态是什么意思,所以我展示了如何在代码中使用 amCharts 的模态,并在注释中展示了使用 amCharts 的弹出窗口的方法。这是我们关于弹出窗口和模式的指南:https://www.amcharts.com/docs/v4/concepts/popups-and-modals/
要触发事件,您可以使用对象的 dispatch
或 dispatchImmediately
方法。所以你发现 polygonSeries.getPolygonById("CA")
。它看起来像 polygonSeries.getPolygonById("CA").dispatchImmediately("hit")
,例如:
// External button that interacts with map, triggers click event of a MapPolygon
var $button = document.getElementById("external-interaction");
chart.events.on("inited", function(event) {
$button.style.display = "inline-block";
$button.addEventListener("click", function(event) {
event.preventDefault();
polygonSeries.getPolygonById("CA").dispatchImmediately("hit");
});
});
这是一个将所有内容放在一起的演示:
https://codepen.io/team/amcharts/pen/9b6d270e43c4a6d32a955fd7ac9a65c9?editors=0011
让我们知道这是否有意义并且是否与您想要做的事情一致。
我需要帮助找到一种方法来在 v4 中从 amcharts v3 复制以下功能但没有成功:
在 V3 中:map.clickMapObject(map.getObjectById('CA')); 在 V4 中:chart.METHOD???(polygonSeries.getPolygonById("CA"))
我在这里想要实现的是通过单击地图外的元素打开区域模式。
谢谢
在 v4 中,您可以在 polygonSeries.mapPolygons.template
上分配一个 hit
事件 (our Events guide),例如:
// Open modal on click
polygonTemplate.events.on("hit", function(event) {
// chart.closeAllPopups(); // <-- if using an amCharts Popup
chart.openModal(
"The id for " +
event.target.dataItem.dataContext.name +
" is <strong>" +
event.target.dataItem.dataContext.id +
"</strong>."
);
// if using an amCharts popup, replace openModal with openPopup
});
不确定区域模态是什么意思,所以我展示了如何在代码中使用 amCharts 的模态,并在注释中展示了使用 amCharts 的弹出窗口的方法。这是我们关于弹出窗口和模式的指南:https://www.amcharts.com/docs/v4/concepts/popups-and-modals/
要触发事件,您可以使用对象的 dispatch
或 dispatchImmediately
方法。所以你发现 polygonSeries.getPolygonById("CA")
。它看起来像 polygonSeries.getPolygonById("CA").dispatchImmediately("hit")
,例如:
// External button that interacts with map, triggers click event of a MapPolygon
var $button = document.getElementById("external-interaction");
chart.events.on("inited", function(event) {
$button.style.display = "inline-block";
$button.addEventListener("click", function(event) {
event.preventDefault();
polygonSeries.getPolygonById("CA").dispatchImmediately("hit");
});
});
这是一个将所有内容放在一起的演示:
https://codepen.io/team/amcharts/pen/9b6d270e43c4a6d32a955fd7ac9a65c9?editors=0011
让我们知道这是否有意义并且是否与您想要做的事情一致。