首页 > 解决方案 > AmCharts4 删除地图图表中的大陆

问题描述

@amcharts/amcharts4-geodata/worldLow"用来创建一个简单的地图,但不需要南极洲。有没有办法隐藏或删除它,但地图利用南极洲留下的空间来使地图相应地调整并使其他大陆更加突出?

初始化代码:

import * as am4maps from "@amcharts/amcharts4/maps";
import am4geodata_worldLow from "@amcharts/amcharts4-geodata/worldLow";
import am4themes_animated from "@amcharts/amcharts4/themes/animated";

let chart = am4core.create("globediv", am4maps.MapChart);

try {
    chart.geodata = am4geodata_worldLow;
} catch (e) {
  chart.raiseCriticalError(new Error("Map geodata could not be loaded."));
}

chart.projection = new am4maps.projections.Projection;
chart.panBehavior = "move";

let polygonSeries = chart.series.push(new am4maps.MapPolygonSeries());
polygonSeries.data = myData;
polygonSeries.useGeodata = true;

想从此视图中删除南极洲并相应调整地图的其余部分

标签: amchartsamcharts4

解决方案


使用此处exclude记录的 polygonSeries 中的属性

polygonSeries.exclude = ["AQ"];

let chart = am4core.create("chartdiv", am4maps.MapChart);

try {
  chart.geodata = am4geodata_worldLow;
} catch (e) {
  chart.raiseCriticalError(new Error("Map geodata could not be loaded."));
}

chart.projection = new am4maps.projections.Miller();
chart.panBehavior = "move";

let polygonSeries = chart.series.push(new am4maps.MapPolygonSeries());
polygonSeries.useGeodata = true;
polygonSeries.exclude = ["AQ"];
#chartdiv {
  width: 100%;
  height: 400px;
 }
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/maps.js"></script>
<script src="https://cdn.amcharts.com/lib/4/geodata/worldLow.js"></script>
<div id="chartdiv"></div>


推荐阅读