将 Highcharts 地图与 React 组件集成

Integrate Highcharts maps with react component

我正在尝试将 highcarts 集成到 React 组件中。

这是我的反应组件代码

import * as Highcharts from 'highcharts/highmaps'
class RealTime extends Component {
  componentDidMount() {
      $.getJSON(     'https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/world-population-density.json',
        function(data) {
          $.each(data, function() {
            this.value = this.value < 1 ? 1 : this.value
          })
          Highcharts.mapChart('world_map', {
            chart: {
              map: 'custom/world'
            },
            title: {
              text: 'Fixed tooltip with HTML'
            },
            legend: {
              title: {
                text: 'Population density per km²',
                style: {
                  color:
                    (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
              }
            },
            mapNavigation: {
              enabled: true,
              buttonOptions: {
                verticalAlign: 'bottom'
              }
            }, 
            series: [
              {
                data: data,
                mapData: Highcharts.maps['custom/world'],
                joinBy: ['iso-a3', 'code3'],
                name: 'Population density',
                states: {
                  hover: {
                    color: '#a4edba'
                  }
                }
              }
            ]
          })
        }
      )
  }

  render() {
    return (
      <div>
        <div className="map_bg" id="world_map"/>
      </div>
    )
  }
}

但是上面的代码既没有显示地图,也没有显示我的反应组件中的任何错误。谁能帮帮我吗 我在这里缺少什么?

谢谢!!!

您需要添加并导入 word.js 脚本:

import Highcharts from "highcharts/highmaps";
import customWord from "./word.js";

现场演示:https://codesandbox.io/s/v0x5zx6q05

此外,我可以推荐您使用 highcharts-react-official 包装器:https://www.npmjs.com/package/highcharts-react-official