niklasmartin
Posts: 3
Joined: Wed Feb 15, 2023 8:48 am

Failing to reproduce example "Animated lines on a world map" in Angular

Hi everyone,

For an Angular project, I'm trying to do something similar to the "Animated lines on a world map" example posted here: https://www.highcharts.com/demo/maps/animated-mapline. Unfortunately, I get many errors when I try to reproduce the map in Angular.

I have these versions installed:

Code: Select all

"@angular/core": "14.2.12",
"highcharts": "~10.3.3",
"highcharts-angular": "~3.0.0",
"@highcharts/map-collection": "~2.0.1",
This is my HTML:

Code: Select all

<highcharts-chart id="container" [Highcharts]="Highcharts" [constructorType]="chartConstructor" [options]="chartOptions"
    style="width: 100%; height: 400px; display: block;">
</highcharts-chart>

This is my Typescript code:

Code: Select all

import { Component, OnInit, Input } from '@angular/core';

import * as Highcharts from 'highcharts';
import HC_map from 'highcharts/modules/map';
HC_map(Highcharts);
import worldMap from "@highcharts/map-collection/custom/world.topo.json";

@Component({
  selector: 'app-gas-flow-map',
  templateUrl: './gas-flow-map.component.html',
  styleUrls: ['./gas-flow-map.component.scss']
})
export class GasFlowMapComponent implements OnInit {

  Highcharts: typeof Highcharts = Highcharts;
  chartConstructor = "mapChart";

  data = [
    {
      'hc-key': 'ye',
      color: '#ffa500',
      info: 'Yemen is where coffee took off.'
    },
    {
      'hc-key': 'br',
      color: '#c0ffd5',
      info: 'Coffee came from La Reunion.'
    },
    {
      'hc-key': 'fr',
      color: '#c0ffd5',
      info: 'Coffee came from Java.'
    },
    {
      'hc-key': 'gb',
      color: '#c0ffd5',
      info: 'Coffee came from Java.'
    },
    {
      'hc-key': 'id',
      color: '#c0ffd5',
      info: 'Coffee came from Yemen.'
    },
    {
      'hc-key': 'nl',
      color: '#c0ffd5',
      info: 'Coffee came from Java.'
    },
    {
      'hc-key': 'gu',
      color: '#c0ffd5',
      info: 'Coffee came from France.'
    },
    {
      'hc-key': 're',
      color: '#c0ffd5',
      info: 'Coffee came from Yemen.'
    },
    {
      'hc-key': 'in',
      color: '#c0ffd5',
      info: 'Coffee came from Yemen.'
    }
  ];

  chartOptions: Highcharts.Options = {
    chart: {
      map: worldMap
    },

    title: {
      text: 'The history of the coffee bean ☕'
    },
    legend: {
      enabled: false
    },
    tooltip: {
      useHTML: true,
      headerFormat: '<b>{point.key}</b>:<br/>',
      pointFormat: '{point.info}'
    },

    mapView: {
      fitToGeometry: {
        type: 'MultiPoint',
        coordinates: [
          // Alaska west
          [-164, 54],
          // Greenland north
          [-35, 84],
          // New Zealand east
          [179, -38],
          // Chile south
          [-68, -55]
        ]
      }
    },

    series: [
      {
        data: this.data,
        keys: ['hc-key', 'color', 'info'],
        name: 'Coffee',
        states: {
          hover: {
            color: '#a4edba'
          }
        }
      },
      {
        type: 'mapline',
        data: [
          {
            geometry: {
              type: 'LineString',
              coordinates: [
                [48.516388, 15.552727], // Yemen
                [110.004444, -7.491667] // Java
              ]
            },
            className: 'animated-line',
            color: '#666'
          },
          {
            geometry: {
              type: 'LineString',
              coordinates: [
                [48.516388, 15.552727], // Yemen
                [55.5325, -21.114444] // La reunion
              ]
            },
            className: 'animated-line',
            color: '#666'
          },
          {
            geometry: {
              type: 'LineString',
              coordinates: [
                [55.5325, -21.114444], // La reunion
                [-43.2, -22.9] // Brazil
              ]
            },
            className: 'animated-line',
            color: '#666'
          },
          {
            geometry: {
              type: 'LineString',
              coordinates: [
                [48.516388, 15.552727], // Yemen
                [78, 21] // India
              ]
            },
            className: 'animated-line',
            color: '#666'
          },
          {
            geometry: {
              type: 'LineString',
              coordinates: [
                [110.004444, -7.491667], // Java
                [4.9, 52.366667] // Amsterdam
              ]
            },
            className: 'animated-line',
            color: '#666'
          },
          {
            geometry: {
              type: 'LineString',
              coordinates: [
                [-3, 55], // UK
                [-61.030556, 14.681944] // Antilles
              ]
            },
            className: 'animated-line',
            color: '#666'
          },
          {
            geometry: {
              type: 'LineString',
              coordinates: [
                [2.352222, 48.856613], // Paris
                [-53, 4] // Guyane
              ]
            },
            className: 'animated-line',
            color: '#666'
          }
        ],
        lineWidth: 2,
        enableMouseTracking: false
      },
      {
        type: 'mappoint',
        color: '#333',
        dataLabels: {
          format: '<b>{point.name}</b><br><span style="font-weight: normal; opacity: 0.5">{point.custom.arrival}</span>',
          align: 'left',
          verticalAlign: 'middle'
        },
        data: [
          {
            name: 'Yemen',
            geometry: {
              type: 'Point',
              coordinates: [48.516388, 15.552727] // Yemen
            },
            custom: {
              arrival: 1414
            },
            dataLabels: {
              align: 'right'
            }
          },
          {
            name: 'Java',
            geometry: {
              type: 'Point',
              coordinates: [110.004444, -7.491667] // Java
            },
            custom: {
              arrival: 1696
            }
          },
          {
            name: 'La Reunion',
            geometry: {
              type: 'Point',
              coordinates: [55.5325, -21.114444] // La reunion
            },
            custom: {
              arrival: 1708
            }
          },
          {
            name: 'Brazil',
            geometry: {
              type: 'Point',
              coordinates: [-43.2, -22.9] // Brazil
            },
            custom: {
              arrival: 1770
            },
            dataLabels: {
              align: 'right'
            }
          },
          {
            name: 'India',
            geometry: {
              type: 'Point',
              coordinates: [78, 21] // India
            },
            custom: {
              arrival: 1670
            }
          },
          {
            name: 'Amsterdam',
            geometry: {
              type: 'Point',
              coordinates: [4.9, 52.366667] // Amsterdam
            },
            custom: {
              arrival: 1696
            }
          },
          {
            name: 'Antilles',
            geometry: {
              type: 'Point',
              coordinates: [-61.030556, 14.681944] // Antilles
            },
            custom: {
              arrival: 1714
            },
            dataLabels: {
              align: 'right'
            }
          },
          {
            name: 'Guyane',
            geometry: {
              type: 'Point',
              coordinates: [-53, 4] // Guyane
            },
            custom: {
              arrival: 1714
            },
            dataLabels: {
              align: 'right'
            }
          }
        ],
        enableMouseTracking: false
      }
    ]
  }




  ngOnInit() {

  }

}

This leads to the following errors. They repeat for every occurrence in the options, here is a list of the unique errors I encounter:

Code: Select all

Property 'type' is missing in type '{ data: { 'hc-key': string; color: string; info: string; }[]; keys: string[]; name: string; states: { hover: { color: string; }; }; }' but required in type 'SeriesXrangeOptions'.

Type '{ geometry: { type: "LineString"; coordinates: number[][]; }; className: string; color: string; }' is not assignable to type 'number | [string, number | null] | SeriesMaplineDataOptions | null'.
  Object literal may only specify known properties, and 'className' does not exist in type '[string, number | null] | SeriesMaplineDataOptions'.
124             className: 'animated-line'

Type '{ name: string; geometry: { type: "Point"; coordinates: number[]; }; custom: { arrival: number; }; dataLabels: { align: "right"; }; }' is not assignable to type 'number | [number, number | null] | SeriesMappointDataOptions | null'.
  Object literal may only specify known properties, and 'custom' does not exist in type '[number, number | null] | SeriesMappointDataOptions'.

212             custom: {
                ~~~~~~~~~
213               arrival: 1414
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
214             },

I can find all these properties in the documentation. Am I doing something wrong? Or does highcharts-angular not support all of the properties of Highcharts?

Thanks for any replies in advance and greetings from the Azores,
Nik
niklasmartin
Posts: 3
Joined: Wed Feb 15, 2023 8:48 am

Re: Failing to reproduce example "Animated lines on a world map" in Angular

I have also reproduced the example on StackBlitz: https://stackblitz.com/edit/angular-j97 ... rc/main.ts and get the same errors.
niklasmartin
Posts: 3
Joined: Wed Feb 15, 2023 8:48 am

Re: Failing to reproduce example "Animated lines on a world map" in Angular

I was able to fix it by removing the type annotation of chartOptions :)
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Failing to reproduce example "Animated lines on a world map" in Angular

Hello and welcome to our forum!

I'm glad you managed to solve the problem and thanks for sharing the solution on the forum.

In case of any further questions, feel free to contact us.
Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/

Return to “Highcharts Maps”