Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误类型错误:无法读取属性';0';角度海图中未定义的_Javascript_Angular_Highcharts - Fatal编程技术网

Javascript 错误类型错误:无法读取属性';0';角度海图中未定义的

Javascript 错误类型错误:无法读取属性';0';角度海图中未定义的,javascript,angular,highcharts,Javascript,Angular,Highcharts,我正在使用angular5和angular highcharts库从highcharts演示中绘制这个简单的地图:如下所示: app.component.ts: import {Component, OnInit, Injectable} from '@angular/core'; import {Chart, MapChart} from 'angular-highcharts'; const Highcharts = {maps: {}}; require('../assets/maps'

我正在使用
angular5
angular highcharts
库从
highcharts
演示中绘制这个简单的地图:如下所示:

app.component.ts:

import {Component, OnInit, Injectable} from '@angular/core';
import {Chart, MapChart} from 'angular-highcharts';

const Highcharts = {maps: {}};
require('../assets/maps')(Highcharts);

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'Spatial Accessibility';
  mapSpatial: MapChart;

  constructor(private http: HttpClient) {
  }

  ngOnInit() {
    this.mapSpatial = this.getEuropeMap();   
  }

  getEuropeMap() {    
    // Instantiate the map
    return new MapChart({
      chart: {
        map: Highcharts['maps']['custom/europe'],
        spacingBottom: 20
      },
      title: {
        text: 'Europe time zones'
      },
      legend: {
        enabled: true
      },
      plotOptions: {
        map: {
          allAreas: false,
          joinBy: ['iso-a2', 'code'],
          dataLabels: {
            enabled: true,
            color: '#FFFFFF',
            style: {
              fontWeight: 'bold'
            },
            // Only show dataLabels for areas with high label rank
            format: null,
            formatter: function () {
              if (this.point.properties && this.point.properties.labelrank.toString() < 5) {
                return this.point.properties['iso-a2'];
              }
            }
          },
          tooltip: {
            headerFormat: '',
            pointFormat: '{point.name}: <b>{series.name}</b>'
          }
        }
      },
      series: [{
        name: 'UTC',
        data: ['IE', 'IS', 'GB', 'PT'].map(code => {
          return {code: code};
        })
      }, {
        name: 'UTC + 1',
        data: ['NO', 'SE', 'DK', 'DE', 'NL', 'BE', 'LU', 'ES', 'FR', 'PL', 'CZ', 'AT', 'CH', 'LI', 'SK', 'HU',
          'SI', 'IT', 'SM', 'HR', 'BA', 'YF', 'ME', 'AL', 'MK'].map(code => {
          return {code: code};
        })
      }, {
        name: 'UTC + 2',
        data: ['FI', 'EE', 'LV', 'LT', 'BY', 'UA', 'MD', 'RO', 'BG', 'GR', 'TR', 'CY'].map(code => {
          return {code: code};
        })
      }, {
        name: 'UTC + 3',
        data: [{
          code: 'RU'
        }]
      }]
    });
  }
}

挣扎了几个小时后,发现
app.module.ts
文件中的双重地图声明正在扰乱配置。从“highcharts/modules/map.src”中删除
import*as maps
和从
providers中删除
maps
修复了这个问题

在代码中添加stackblitz或类似的工具将帮助您更快地获得答案。不过,在创建stackblitz时解决了这个问题,谢谢!你节省了我的时间!!谢谢兄弟!!
ERROR TypeError: Cannot read property '0' of undefined
    at eval (webpack-internal:///./node_modules/highcharts/modules/map.src.js:64)
    at Array.forEach (<anonymous>)
    at a.each (webpack-internal:///./node_modules/highcharts/highcharts.js:28)
    at G.eval (webpack-internal:///./node_modules/highcharts/modules/map.src.js:60)
    at eval (webpack-internal:///./node_modules/highcharts/highcharts.js:30)
    at Array.forEach (<anonymous>)
    at Object.a.each (webpack-internal:///./node_modules/highcharts/highcharts.js:28)
    at a.fireEvent (webpack-internal:///./node_modules/highcharts/highcharts.js:30)
    at G.getSeriesExtremes (webpack-internal:///./node_modules/highcharts/highcharts.js:127)
    at G.setScale (webpack-internal:///./node_modules/highcharts/highcharts.js:146)
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import {ChartModule, HIGHCHARTS_MODULES} from 'angular-highcharts';
import * as more from 'highcharts/highcharts-more.src';
import * as highstock from 'highcharts/modules/stock.src';
import * as highmaps from 'highcharts/modules/map.src';
import * as maps from 'highcharts/modules/map.src';
import * as noData from 'highcharts/modules/no-data-to-display.src';
import * as drilldown from 'highcharts/modules/drilldown.src';
import {AppComponent} from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ChartModule,
    HttpClientModule
  ],
  providers: [{
    provide: HIGHCHARTS_MODULES, useFactory: () => {
      return [highstock, more, maps, noData, drilldown, highmaps];
    }
  }],
  bootstrap: [AppComponent],
  exports: [
    ChartModule
  ]
})
export class AppModule {
}