echarts icon indicating copy to clipboard operation
echarts copied to clipboard

react+echarts引入地图,import显示Map world not exists

Open RelaxLiu opened this issue 9 years ago • 5 comments

One-line summary [问题简述]

用react开发,应用世界地图(中国地图一样问题),使用import引入地图文件浏览器报Map world not exists错误。 import ECharts from 'echarts/dist/echarts.js'; import 'echarts/lib/chart/map.js'; import 'echarts/map/js/world.js'; 案例显示 但是地图不显示

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]:3.3.1
  • Browser version [浏览器类型和版本]:谷歌
  • OS Version [操作系统类型和版本]:mac

Expected behaviour [期望结果]

地图显示

ECharts option [ECharts配置项]

option = {

}

var latlong = {};
latlong.AD = {'latitude':42.5, 'longitude':1.5};
latlong.AE = {'latitude':24, 'longitude':54};
latlong.AF = {'latitude':33, 'longitude':65};。。。。。
var mapData = [
{'code':'AF' , 'name':'Afghanistan', 'value':32358260, 'color':'#eea638'},
{'code':'AL' , 'name':'Albania', 'value':3215988, 'color':'#d8854f'},
{'code':'DZ' , 'name':'Algeria', 'value':35980193, 'color':'#de4c4f'},。。。。


let MapOption = {
    backgroundColor: '#fff',
    title : {
        text: 'World Population (2011)',
        subtext: 'From Gapminder',
        left: 'center',
        top: 'top',
        textStyle: {
            color: '#fff'
        }
    },
    tooltip : {
        trigger: 'item',
        formatter : function (params) {
            var value = (params.value + '').split('.');
            value = value[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,')
                    + '.' + value[1];
            return params.seriesName + '<br/>' + params.name + ' : ' + value;
        }
    },
    visualMap: {
        show: false,
        min: 0,
        max: max,
        inRange: {
            symbolSize: [6, 60]
        }
    },
    geo: {
        name: 'World',
        type: 'map',
        map: 'world',
        roam: true,
        label: {
            emphasis: {
                show: false
            }
        },
        itemStyle: {
            normal: {
                areaColor: '#323c48',
                borderColor: '#111'
            },
            emphasis: {
                areaColor: '#2a333d'
            }
        }
    },
    series : [
        {
            type: 'scatter',
            coordinateSystem: 'geo',
            data: mapData.map(function (itemOpt) {
                return {
                    name: itemOpt.name,
                    value: [
                        latlong[itemOpt.code].longitude,
                        latlong[itemOpt.code].latitude,
                        itemOpt.value
                    ],
                    label: {
                        emphasis: {
                            position: 'right',
                            show: true
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: itemOpt.color
                        }
                    }
                };
            })
        }
    ]
};


componentDidMount: function(){
		let myMap = ECharts.init(document.getElementById('main'));
		myMap.setOption(MapOption);
		$(window).resize(function(){
		  myMap.resize();
		})
  },


### Other comments [其他信息]
<!-- For example: Screenshot or Online demo -->
<!-- [例如,截图或线上实例 (JSFiddle/JSBin/Codepen)] -->

RelaxLiu avatar Dec 26 '16 07:12 RelaxLiu

可能因为引入的问题有两个 echarts 的命名空间了,你排查下

pissang avatar Dec 26 '16 07:12 pissang

您好方便加您一下么,详细询问下

RelaxLiu avatar Dec 26 '16 08:12 RelaxLiu

@pissang 为什么我的是空白 也不报错

SynChron1zed avatar Apr 06 '17 10:04 SynChron1zed

@SynChron1zed 我的也是。空白,也不报错

coffeexy avatar Jul 05 '18 11:07 coffeexy

What is exact issue

shivakumarprabha avatar Aug 27 '18 12:08 shivakumarprabha