美文网首页
vue使用echarts画省份地图

vue使用echarts画省份地图

作者: 银角大王__ | 来源:发表于2019-12-25 10:25 被阅读0次

vue中使用echarts画省份地图

1.安装echarts

npm install echarts --save

2.引入echarts

// 在main.js中引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts;
  1. 示例
<template>
 <div class="maps-container">
   <div id="main" style="width:100%; height:100%"></div>
 </div>
</template>
<script>
import "echarts/map/js/province/yunnan.js";
import obj from "echarts/map/json/province/yunnan.json";
export default {
 data() {
   return {
     listArr: [], //城市json
     max: "", //最大value值
     min: "" // 最小value值
   };
 },
 created() {
   this.getData();
 },
 mounted() {
   this.DrawMap();
 },
 methods: {
   getData() {
     // 获取城市名称数据
     console.log("取到的云南省的json数据", obj);
     if (obj) {
       let arr = obj.features;
       // 循环取出 城市名称和value值
       for (var j = 0; j < arr.length; j++) {
         this.max = arr[0].id;
         this.min = arr[0].id;
         if (arr[j].id > this.max) {
           this.max = arr[j].id;
         }
         if (arr[j].id < this.min) {
           this.min = arr[j].id;
         }
         this.listArr.push({
           name: arr[j].properties.name,
           value: arr[j].id
         });
       }
     }
   },
   DrawMap() {
     let _this = this;
     let myChart8 = this.$echarts.init(document.getElementById("main"));
     console.log(
       "最大value值",
       this.max,
       "\n",
       "最小value值",
       this.min,
       "\n",
       "城市数据",
       this.listArr
     );
     myChart8.setOption({
       visualMap: {
         min: _this.min,
         max: _this.max,
         show: false,
         inRange: {
           color: ["lightskyblue", "yellow", "orangered"]
         }
       },
       series: [
         {
           type: "map",
           map: "云南",
           itemStyle: {
             normal: { label: { show: true } },
             emphasis: { label: { show: true } },
             emphasis: {
               areaColor: "#67C23A" //鼠标进入时的颜色
             }
           },
           data: _this.listArr
         }
       ]
     });
   }
 }
};
</script>
<style scoped lang="scss">
.maps-container {
 width: 100%;
 height: 100%;
}
</style>

yunan.png

相关文章

网友评论

      本文标题:vue使用echarts画省份地图

      本文链接:https://www.haomeiwen.com/subject/zenqoctx.html