如何在ammap

时间:2016-12-07 11:38:10

标签: javascript json amcharts ammap

我想在ammap上使用dataloader功能,但我无法获得。

以下是我尝试的方法:

var dogum_map = AmCharts.makeChart( "il_bazinda_dogum_say_dagilim", {
                  "type": "map",
                  "data": {
                        "map": "turkeyLow"
                    },
                  "theme": "light",
                  "colorSteps": 10,
                  "dataLoader": {
                        "url": "/dogum/dogum_frekans_verilerini_il_bazinda_hesapla",
                        "format": "json",
                        "showErrors": true
                  },
                  "areasSettings": {
                    "autoZoom": false,
                    "balloonText": "[[value]]",
                    "selectable":true
                  },

                  "valueLegend": {
                    "right": 10,
                    "minValue": "En Az",
                    "maxValue": "En Çok"
                  },

                  "export": {
                    "enabled": true,
                    "fileName":"İl Bazında Doğum Sayıları"
                  }

                } );

json url没有问题。这个url返回这样的json数据:

[{"id":"TR-01","ndogum":1111,"mdogum":22,"sdogum":693,"pdogum":336,"total":2162},{"id":"TR-02","ndogum":423,"mdogum":0,"sdogum":325,"pdogum":147,"total":895},{"id":"TR-03","ndogum":199,"mdogum":1,"sdogum":113,"pdogum":42,"total":355},{"id":"TR-04","ndogum":681,"mdogum":17,"sdogum":180,"pdogum":117,"total":995}]

我希望在地图value上用作total

如何在ammap上使用dataloader

由于

1 个答案:

答案 0 :(得分:0)

要将dataLoader与地图库一起使用,您的数据需要与地图的dataProvider对象格式相同,其中包含map属性和areas数组。如果您的数据没有以这种方式格式化,那么您可以使用dataLoader的postProcess回调来创建dataProvider对象,并将其与您的数据一起返回。您还需要将总属性重新映射到数据中的值,以便气球和图例可以正常工作。

这是dataLoader代码:

  "dataLoader": {
    "url": "/dogum/dogum_frekans_verilerini_il_bazinda_hesapla",
    "postProcess": function(data) {
      var dataProvider = {
        "map": "turkeyLow"
      };
      //create new areas array, while adding a value property 
      //to each area containing the value stored in total
      dataProvider.areas = data.map(function(area) {
        area.value = area.total;
        return area;
      });
      return dataProvider;
    }
  },

Codepen demo