安裝v-charts
npm安裝
$ npm install echarts vue-echarts
在使用v-chart前必須安裝echarts
在main.js中進行注冊
import ECharts from 'vue-echarts'
Vue.component('v-chart', ECharts)
在頁面進行使用
1.頁面中使用v-chart
<template>
<v-chart :options="options" />
</template>
- 在頁面中引入百度地圖的js
<script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=你的密鑰"></script>
這里的密鑰需要在百度地圖平臺去申請 免費的 官方地址
3. 在options中進行配置,
<script>
// 引入百度地圖的擴展
import 'echarts/extension/bmap/bmap'
export default {
data () {
return {
options: {
}
}
},
mounted () {
/* eslint-disable */
this.options = {
bmap: {
key: '你的密鑰',
center: [104.114129, 37.550339],
zoom: 5,
roam: false,
mapStyle: { }
}
}
}
}
</script>
最后訪問看效果

自定義樣式
這里可以在 mapStyle: { }中貼入自己想設定的樣式
注意:如果mapStyle樣式不生效,打開package.json查看echarts版本是否是4.7版本
貼一個mapStyle中樣式樣例:
styleJson: [{
'featureType': 'water',
'elementType': 'all',
'stylers': {
'color': '#d1d1d1'
}
}, {
'featureType': 'land',
'elementType': 'all',
'stylers': {
'color': '#f3f3f3'
}
}, {
'featureType': 'railway',
'elementType': 'all',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'highway',
'elementType': 'all',
'stylers': {
'color': '#fdfdfd'
}
}, {
'featureType': 'highway',
'elementType': 'labels',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'arterial',
'elementType': 'geometry',
'stylers': {
'color': '#fefefe'
}
}, {
'featureType': 'arterial',
'elementType': 'geometry.fill',
'stylers': {
'color': '#fefefe'
}
}, {
'featureType': 'poi',
'elementType': 'all',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'green',
'elementType': 'all',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'subway',
'elementType': 'all',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'manmade',
'elementType': 'all',
'stylers': {
'color': '#d1d1d1'
}
}, {
'featureType': 'local',
'elementType': 'all',
'stylers': {
'color': '#d1d1d1'
}
}, {
'featureType': 'arterial',
'elementType': 'labels',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'boundary',
'elementType': 'all',
'stylers': {
'color': '#fefefe'
}
}, {
'featureType': 'building',
'elementType': 'all',
'stylers': {
'color': '#d1d1d1'
}
}, {
'featureType': 'label',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#999999'
}
}]
效果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/305479.html
標籤:其他
上一篇:Echarts餅圖常用效果
下一篇:JavaScript之手撕new
