xieziyu / ngx-echarts

An angular (ver >= 2.x) directive for ECharts (ver >= 3.x)
https://xieziyu.github.io/ngx-echarts/
MIT License
1.11k stars 197 forks source link

registerMap china-cities.json error #255

Closed carrie-xin closed 4 years ago

carrie-xin commented 4 years ago

I'm using ngx-echarts to render china cities map on my dashboard, but somthing error happend image

here's my package version and main code

 <div class="chart-wrapper">
     <div class="chart-div" echarts [options]="chinaMapOption" (chartInit)="chinaMapInit($event)"
            [autoResize]="true"></div>
 </div>

  // components
  import * as echarts from "echarts";
  import * as citiesJson from "echarts/map/json/china-cities.json";

  private  mapValue = [
    {
      name: "北京市",
      value: [116.407526, 39.90403, 4133000, "35"]
    },
    {
      name: "上海市",
      value: [121.473701, 31.230416, 1951000, "16"]
    }];

  public chinaMapOption= {
    geo: {
      map: 'china',
      ...
    },
    series: [
      {
        name: 'dashboard',
        type: 'scatter', 
        coordinateSystem: 'geo', 
        data: this.mapValue 
        ...
      }
    ]
  };

  public chinaMapInit(ec) {
   echarts.registerMap('china', citiesJson);
    this.instance.chinaMap = ec;
  }

Is there anyway to solve this problem?

xieziyu commented 4 years ago

@carrie-xin You need to registerMap before you try to init the echarts. You can call it in app.module.ts or somewhere else

carrie-xin commented 4 years ago

@xieziyu thank you for your response, but it seems the problem of import json, when i change

import * as citiesJson from "echarts/map/json/china-cities.json";

to

import  citiesJson from "echarts/map/json/china-cities.json";

it works fine for me.

henriquechagasg commented 2 years ago

@carrie-xin You need to registerMap before you try to init the echarts. You can call it in app.module.ts or somewhere else

Whats the best way to do that ?