apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.41k stars 19.61k forks source link

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

Closed 87265822 closed 3 years ago

87265822 commented 7 years ago

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格式也没有问题。

MrChanLi2013 commented 7 years ago

@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)
    }
  }
imageslr commented 7 years ago

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

MrChanLi2013 commented 7 years ago

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

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

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

guo897654050 commented 5 years ago

这个咋解决的,求教

github-actions[bot] commented 3 years ago

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] commented 3 years ago

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!