echarts icon indicating copy to clipboard operation
echarts copied to clipboard

在vue2.x中使用echarts,地图或者theme引入js 文件,会有问题,地图的json文件重新注册可以

Open 87265822 opened this issue 9 years ago • 7 comments

One-line summary [问题简述]

在vue2.x中使用echarts,地图或者theme引入会有问题

import echarts from 'echarts/dist/echarts';
import macaronsfrom 'echarts/theme/macarons';//shine roma macarons
//require('echarts/theme/macarons');

export default {
	data () {
		return {
			msg: 'Hello Vue!'
		}
	},
	mounted: function() {
    	    this.myChart = echarts.init(document.getElementById('main'), 'macarons');
                var option = {...}
               this.myChart.setOption(option);
	}
}

不管是map还是theme,js类型的,import之后,都没有效果 我试了map的json格式,再用echarts.registerMap,地图就可以。 import china from 'echarts/map/json/china.json'; echarts.registerMap('china', china);

我查看了chian.js里面的代码,怀疑是echarts.registerMap这边有问题。

Expected behaviour [期望结果]

希望官网提供的js格式也没有问题。

87265822 avatar Jun 29 '17 06:06 87265822

@87265822 我也使用vue,使用npm install echarts之后,在echarts/map/js中是有地图相关的js,你可以直接

   import echarts from 'echarts'
   require('echarts/map/js/china.js')
   
   export default {
     ...
     mounted () {
      let myChart = echarts.init(document.getElementById('graph'))
      let option = {
      ...
      }
      myChart.setOption(option)
    }
  }

MrChanLi2013 avatar Jul 24 '17 08:07 MrChanLi2013

@MrChanLi2013 我很奇怪,为什么我require我自己下载的china.js就报错“echart not loaded”呢? 除了和echarts/map/js路径不同以外,其他的完全相同

imageslr avatar Aug 23 '17 04:08 imageslr

@imageslr 如果是自己单独引入的推荐使用加载json的方式:

// import echarts from './../../../static/echarts/echarts.js' 这里是引入echarts本地文件
echarts.registerMap('china', '你的china.json文件')

MrChanLi2013 avatar Aug 28 '17 02:08 MrChanLi2013

我遇到了和你一样的问题,暂时不知道如何解决。

guoliangli123 avatar Sep 20 '17 02:09 guoliangli123

这个咋解决的,求教

guo897654050 avatar Jan 13 '19 13:01 guo897654050

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.

github-actions[bot] avatar Sep 03 '21 08:09 github-actions[bot]

This issue has been automatically closed because it did not have recent activity. If this remains to be a problem with the latest version of Apache ECharts, please open a new issue and link this to it. Thanks!

github-actions[bot] avatar Sep 10 '21 21:09 github-actions[bot]