将Highcharts地图与反应组件集成

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

我试图将highcarts整合到反应组件中。

这是我的反应组件的代码

import * as Highcharts from 'highcharts/highmaps'
class RealTime extends Component {
  componentDidMount() {
      $.getJSON(     'https://cdn.jsdelivr.net/gh/highcharts/[email protected]/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>
    )
  }
}

但是上面的代码没有显示我的react组件中的map或任何错误。谁能帮助我,我在这里缺少什么?

谢谢!!!

javascript reactjs highcharts react-highcharts
1个回答
3
投票

您需要添加和导入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

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