TypeError:Highcharts.mapChart不是函数

问题描述 投票:-2回答:1

我正在尝试使用打字稿来绘制高图。我还加载了包含highmaps的highcharts类型。

class InvestmentChart extends React.Component {
  componentDidMount() {
    Highcharts.mapChart("investment", {
      chart: {
...

干杯

看到现场here

reactjs typescript highcharts
1个回答
3
投票

基于readme,看起来你需要这样做:

import * as Highcharts from 'highcharts/highmaps';

代替:

import * as Highcharts from 'highcharts';

我尝试了这个in CodeSandbox,它似乎超过了你被卡住的地步。

更新

DefinitelyTyped似乎有一些Highmaps的类型,虽然它们已经过时了。以下导入Highmaps的方法似乎在运行时在CodeSandbox中获得前一个方法,并将使用以下类型:

import * as Highcharts from "highcharts";
import MapFactory = require("highcharts/modules/map");
(MapFactory as any)(Highcharts);

New CodeSandbox。在本地,我仍然得到一个类型错误,因为过时的声明(subtitle无法识别),但你可以//@ts-ignore它。我不知道为什么CodeSandbox上没有出现此错误。

© www.soinside.com 2019 - 2024. All rights reserved.