在Amcharts 4上悬停一组国家,而不是一个国家

时间:2018-08-07 09:44:24

标签: angular typescript maps amcharts

这是我的问题。 我将地图上的所有国家/地区(EMEA,NA,APAC,LATAM)分组。 现在,在“悬停”上,我不想突出显示单个国家,而是整个区域。

您对此有何建议?

这是我当前的代码:

his.regions[name] = this.map.series.push(new am4maps.MapPolygonSeries());
   this.regions[name].name = name;
   this.regions[name].useGeodata = true;
   this.regions[name].include = values;
   this.regions[name].mapPolygons.template.tooltipText = name;
   this.regions[name].mapPolygons.template.fill = am4core.color('#000000');
   this.regions[name].fill = am4core.color('#000000');

   const hs = this.regions[name].mapPolygons.template.states.create('hover');
   hs.properties.fill = am4core.color('#D0021B');
   this.regions[name].mapPolygons.template.propertyFields.fill = 'fill';

非常感谢

1 个答案:

答案 0 :(得分:1)

您似乎非常关注the Map tutorial

一种方法是跟踪系列的结束/结束事件并在其mapPolygons上设置适当的状态,这将允许进行精细控制,例如

   this.regions[name].events.on("over", over);
   this.regions[name].events.on("out", out);

   function over(ev) {
     ev.target.mapPolygons.each(function(polygon) {
       polygon.setState("hover");
     });
   }

   function out(ev) {
     ev.target.mapPolygons.each(function(polygon) {
       polygon.setState("default");
     });
   }

示例: https://codepen.io/team/amcharts/pen/pZOXpX

或者,如果您对SpriteStates的处理不多,则可以依靠每个系列的setStateOnChildren布尔属性:

听起来,一旦在系列上设置了状态,则其mapPolygons将触发相同的状态键(如果有)。只需在系列上创建悬停状态即可使其工作:

   this.regions[name].states.create("hover");
   this.regions[name].setStateOnChildren = true;

示例: https://codepen.io/team/amcharts/pen/f28557342c2e59f4f834b342138281df/

相关问题