【问题标题】:AmCharts5 set active state on countryAmCharts5 在国家/地区设置活动状态
【发布时间】:2022-06-17 19:03:14
【问题描述】:

在这个问题上卡了很长时间。 我有一张 amcharts5 地图,我想在其中预先缩放到特定国家/地区并将其状态设置为活动状态。

缩放部分很简单——polygonSeries.zoomToDataItem()

但我似乎无法理解如何将状态设置为活动,在 amchart4 中它很简单 (https://www.amcharts.com/docs/v4/tutorials/pre-zooming-map-to-a-country/#Highlighting_selected_country),但在 amcharts5 中......

谢谢

【问题讨论】:

    标签: amcharts amcharts5


    【解决方案1】:

    知道了!!!

    polygonSeries.mapPolygons.template._entities[9].set("active", true)
    

    9 - 国家索引

    【讨论】:

      【解决方案2】:
      let previousPolygon = null;
      
      polygonSeries.mapPolygons.template.setAll({
        toggleKey: 'active',
      });
      
      polygonSeries.mapPolygons.template.on('active', (active, target) => {
        if (previousPolygon && previousPolygon !== target) {
          previousPolygon.set('active', false);
        }
        if (target.get('active')) {
          polygonSeries.zoomToDataItem(target.dataItem);
        } else {
          chart.goHome();
        }
        previousPolygon = target;
      });
      

      上面的代码允许在点击时放大/缩小并切换目标国家的活动状态 https://www.amcharts.com/demos/zooming-to-countries-map/

      【讨论】:

        猜你喜欢
        • 2019-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-24
        • 1970-01-01
        相关资源
        最近更新 更多