在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这边有问题。
希望官网提供的js格式也没有问题。
@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 我很奇怪,为什么我require我自己下载的china.js就报错“echart not loaded”呢? 除了和echarts/map/js路径不同以外,其他的完全相同
@imageslr 如果是自己单独引入的推荐使用加载json的方式:
// import echarts from './../../../static/echarts/echarts.js' 这里是引入echarts本地文件
echarts.registerMap('china', '你的china.json文件')
我遇到了和你一样的问题,暂时不知道如何解决。
这个咋解决的,求教
Most helpful comment
@87265822 我也使用vue,使用
npm install echarts之后,在echarts/map/js中是有地图相关的js,你可以直接