1

为什么 tooltipPosition = "fixed" 不适用于我的地图?我阅读了文档并按照它说的做了。(https://www.amcharts.com/docs/v4/reference/tooltip/

function addSeries(country, tooltipHTML) {
    let newSeries = chart.series.push(new am4maps.MapPolygonSeries());
    newSeries.useGeodata = true;
    newSeries.include = country;
    newSeries.mapPolygons.template.fill = am4core.color("#4D7EAA");
    newSeries.fill = am4core.color("#4D7EAA");
    newSeries.mapPolygons.template.tooltipText = tooltipHTML;
    newSeries.mapPolygons.template.tooltipHTML = tooltipHTML;
    newSeries.tooltip.getFillFromObject = false;
    newSeries.tooltip.background.fill = am4core.color("#000");
    newSeries.tooltip.tooltipPosition = "fixed";
    newSeries.tooltip.x = 10;
    newSeries.tooltip.trackable = false;
    newSeries.tooltip.y = 30;
    newSeries.mapPolygons.template.events.on("over", over);
    newSeries.mapPolygons.template.events.on("out", out);
    newSeries.cursorOverStyle = am4core.MouseCursorStyle.pointer;
    let hs = newSeries.mapPolygons.template.states.create("hover");
    hs.properties.fill = am4core.color("#004685");
}

完整代码: https ://codepen.io/nefayran/pen/BEmQvE

4

1 回答 1

0

这是一个很好的问题。

请注意文档还说:

继承自雪碧

即属性实际上不是Tooltip实例本身的属性,而是工具提示从触发它的对象获取的属性和行为(并不完全不同tooltipText)。

通常,一个系列上有一个工具提示在其对象之间共享,因此即使在这种情况下每个工具提示都会mapPolygon触发工具提示,但它不是每个多边形的工具提示,而是在一个系列上共享的工具提示(几乎就像一个单例)。这样,当您从 mapPolygon 悬停到 mapPolygon 时,工具提示将保持持续可见并相应地更改属性。

因此,在这种情况下,不要在工具提示本身上设置属性,只需在 mapPolygons 的模板上设置它:

// newSeries.tooltip.tooltipPosition = "fixed";
newSeries.mapPolygons.template.tooltip.tooltipPosition = "fixed";

这是一个叉子:

https://codepen.io/team/amcharts/pen/29890969c7222b7ddba5c9fbeefa80b5

附录(2019-04-17)

问题:悬停在城市(mapImage/其子级)或线(mapLine或变体)上会杀死mapPolygon它触发的悬停效果和线/动画。

解决方案:如果城市/线路没有任何用户交互功能(如工具提示),我的建议是完全禁用交互,因此将鼠标悬停在它们上方会直接进入mapPolygon下方,即

cities.mapImages.template.interactionsEnabled = false;
lineSeries.mapLines.template.interactionsEnabled = false;

上面的演示已更新为包含这些行。

于 2019-04-16T03:02:27.443 回答