温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

vue如何导入echarts地图

发布时间:2021-10-27 17:08:13 阅读:283 作者:小新 栏目:编程语言
Vue开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章主要为大家展示了“vue如何导入echarts地图”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“vue如何导入echarts地图”这篇文章吧。

导入方法:1、使用“npm install echarts -S”命令安装echarts依赖;2、在“main.js”中全局引入echarts;3、在需要地图的页面中使用import语句引入“china.js”文件,添加相关代码即可。

本教程操作环境:windows7系统、vue2.9.6版、DELL G3电脑。

vue如何导入echarts地图

需求:显示各省名字,滑过标记地显示接入数量,点击标记地 显示系统数量已接入及能跳转对应页面信息的入口;

配置:

1.安装依赖

npm install echarts -S

2.全局引入main.js

// 引入echarts
import echarts from 'echarts'
 
Vue.prototype.$echarts = echarts

3.在需要地图的页面引入 地图  china.js   查看官方文档  ,我自己保存的 china.js  点击下载(提取码 4rxi )

import '../../../static/js/chinamap/china.js' // 引入中国地图数据

使用:

完整实例代码:

<template>
  <div class="Page">
    <div id="myChartChina" :style="{width: '100%', height: '710px'}"></div>
    <div class="projectList">
      <div>
        <p> <i class="el-icon-share"></i> 客户数量</p>
        <div class="inputList">3600</div>
      </div>
      <div>
        <p> <i class="el-icon-share"></i> 租户数量</p>
        <div class="inputList">1500</div>
      </div>
      <div>
        <p> <i class="el-icon-share"></i> 控制系统数量</p>
        <div class="inputList">20800</div>
      </div>
      <div>
        <p> <i class="el-icon-share"></i> 接入系统数量</p>
        <div class="inputList">3600</div>
      </div>
    </div>
 
 
    <div id="box" v-if="ifbox">
      <div class="box_left">
        <div class="box_title">{{TipsList.name}}</div>
        <div class="box_list">
          <p>{{TipsList.value[2]}}</p>
          <p>系统数量</p>
        </div>
        <div class="box_list box_lists">
          <p>{{TipsList.num[2]}}</p>
          <p>已接入</p>
        </div>
        <div></div>
      </div>
      <div class="box_right" @click="toClient(TipsList.id[2])">
        <i class="el-icon-arrow-right"></i>
      </div>
    </div>
 
    <div class="box_Tips">
      <p>提示:滚动鼠标滚轮控制地图缩放</p>
    </div>
 
  </div>
  
</template>
 
<script>
import '../../../static/js/chinamap/china.js' // 引入中国地图数据
export default {
  data() {
    return {
      ifbox:false,
      TipsList:[],
    }
  },
  mounted() {
    this.ChinaMap();
  },
  methods: {
    //点击模拟数据右箭头跳转外页面,
    toClient(id){
      this.$router.push({
        path"/Client",
        query: { lesseeCompanyId: id }
      });
    },
    ChinaMap(){
      var that=this;
       
      //模拟数据
      let data = [
          {name'海门'value90 ,num5,id:8},
          {name'鄂尔多斯'value102 , num15id:16},
          {name'齐齐哈尔'value140num30 ,id:20}
      ];
      let geoCoordMap = {
          '海门':[121.15,31.89],
          '鄂尔多斯':[109.781327,39.608266],
          '齐齐哈尔':[123.97,47.33]
      };
 
      var convertData = function(data) {
          var res = [];
          for (var i = 0; i < data.length; i++) {
              var geoCoord = geoCoordMap[data[i].name];
              if (geoCoord) {
                  res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value),
                    num: geoCoord.concat(data[i].num),
                    id: geoCoord.concat(data[i].id)
                  });
              }
          }
          return res;
      };
 
 
      let myChartChina = this.$echarts.init(document.getElementById('myChartChina')) //这里是为了获得容器所在位置    
        window.onresize = myChartChina.resize;
        myChartChina.setOption({ // 进行相关配置
          backgroundColor'#1c2431',//地图背景色
          geo: { // 这个是重点配置区
            map'china'// 表示中国地图
            label: {
              normal:{
                showtrue// 是否显示对应地名
                textStyle: { //字体颜色
                  color'#797979'
                }
              },
              emphasis: {
                showfalse,
                textStyle: {
                  color'#fff'
                }
              }
            },
            roamtrue,
            itemStyle: {
              normal: {
                borderWidth1// 地图边框宽度
                borderColor'#014888'// 地图边框颜色
                areaColor'#026295' // 地图颜色
              },
              emphasis: {//选中省份的颜色
                areaColor'#026295',
                shadowOffsetX0,
                shadowOffsetY0,
                shadowBlur0,
                borderWidth1,
                shadowColor'#fff'
              }
            }
          },
          //滑动显示数据
          tooltip: {
              trigger'item',
              formatterfunction(params) {
                  return params.name + ' 已接入: ' + params.data.num[2];
              }
          },
          series: [{
              name'散点',
              type'scatter',
              coordinateSystem'geo',
              color:"#e1ebe3",//点的颜色
              dataconvertData(data),
              symbolSize25,//点的大小
              symbol:"pin",//点的样式
              cursor:"pointer",//鼠标放上去的效果
              label: {
                normal: {//默认展示
                    showfalse
                },
                emphasis: {//滑过展示
                    showfalse
                }
              },
              itemStyle: {
                emphasis: {
                  borderColor'#5c8f6e',
                  borderWidth5
                }
              }
            },
 
            {
              type'map',
              map'china',
              geoIndex0,
              aspectScale0.75,
              tooltip: {
                  showfalse
              }
            },
              
          ],
        })
        // if (myChartChina && typeof myChartChina === "object") {
        //     myChartChina.setOption(myChartChina, true);
        // }
        myChartChina.on('click'function (params) { //点击事件
          if (params.componentType === 'series') {
            if(params.data){
              that.TipsList=params.data
              that.ifbox=true
              that.boxPosition()
 
            }else{
              that.ifbox=false
            }
          }
        });
    },
    //点击地点显示对应位置数据
    boxPosition(){
      var e = event || window.event;
      var x=e.clientX+145+"px",
          y=e.clientY+5+"px";
      clearTimeout(t)
      var t = setTimeout(function (){
        $('#box').css('top',y),
        $('#box').css('left',x)
      }, 100);
      t
    },
 
  }
  
}
</script>
<style scoped>
.Page{
  position: relative;
}
.projectList{
  position: absolute;
  bottom:0;
  left:0;
  z-index100;
  width280px;
  height150px;
  backgroundlinear-gradient(#1d4978#081630);
  display: flex;
  flex-wrap:wrap;
  justify-content:space-around;
  align-items:center;  
}
.projectList>div{
  width120px;
  height55px;
}
.projectList>div>p{
  color#fff;
  font-size16px;
}
.projectList>div>p>i{
  color#12baf9;
}
.inputList{
  width120px;
  height30px;
  background#1a3c7b;
  border2px solid #0f5390;
  margin-top:7px;
  border-radius5px;
  letter-spacing:5px;
  color#65ddd3;
  line-height26px;
  text-indent1em;
}
 
 
#box{
  width:280px;
  height80px;
  background#026295;
  box-shadow0 0 10px #008b9a;
  border1px solid #008b9a;
  position: absolute;
  top:10px;
  left50%;
  margin-left: -140px;
  color#fff;
  text-align: center;
}
.box_left{
  width239px;
  height80px;
  float: left;
}
.box_title{
  width238px;
  height30px;
  border-bottom1px solid #008b9a;
  line-height30px;
}
.box_list{
  width119px;
  height50px;
  float: left;
}
.box_lists{
  border-left1px solid #008b9a;
}
.box_list>p:nth-child(1){
  font-size20px;
  line-height28px;
  color: yellow;
}
.box_lists>p:nth-child(1){
  colorrgb(111185234);
}
 
.box_right{
  width39px;
  height80px;
  border-left1px solid #008b9a;
  float: left;
}
.box_right i{
  line-height80px;
}
 
 
 
.dilog {
  /* width: 180px; */
  height80px;
  background: black;
  position: absolute;
  border-radius5px;
  border: solid 1px rgb(0139154);
  z-index11111;
  display: flex;
  box-shadow0 0 10px rgb(0139154);
}
.dilog_title {
  text-align: center;
  height30px;
  border-bottom: solid 1px grey;
  line-height30px;
  color: white;
}
.box_Tips{
  width:96%;
  height20px;
  position: absolute;
  bottom5px;
  right5px;
  font-size14px;
  color#fff;
}
.box_Tips>p{
  white-space: nowrap;
  position: absolute;
  top0px;
  left0;
  animation:mymove 30s infinite;
}
@keyframes mymove
{
from {left70%;}
to {left0%;}
}
</style>

以上是“vue如何导入echarts地图”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×