首页 > 其他分享 >vue项目中引入echarts中国地图

vue项目中引入echarts中国地图

时间:2023-04-24 22:25:26浏览次数:36  
标签:map vue color 地图 rgb china 引入 echarts

 最近项目中根据项目需求,展示中国地图

一、下载echarts插件(我这里使用的是 4.9.0 版本)

  npm install [email protected] --save

二、在需要使用的页面引入echarts (这里是单独封装了地图组件)  components/map.vue

<template>
  <div class="map-view">
    <div id="main"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import geoJson from "echarts/map/json/china";
export default {
  data() {
    return {};
  },
  mounted() {
    let myChart = echarts.init(this.$el,document.getElementById("main"));
    // 注册的是中国地图,必须包括geo组件或者mep图标类型的时候才可以使用
    // 地图:世界地图,中国地图,省份地图,市区地图
    echarts.registerMap("china", geoJson);

    myChart.setOption({
      // 背景色
      backgroundColor: "rgb(70, 70, 231)",
      // 配置项(组件)
      geo: {
        map: "china",
        // 地图的长宽比例
        aspectScale: 0.75,
        // 图层
        zoom: 1.1,
        // 样式
        itemStyle: {
          // 标准
          normal: {
            // 地图区域的颜色
            areaColor: {
              type: "radial",
              x: 0.5,
              y: 0.5,
              r: 0.8,
              // 颜色的步骤
              colorStops: [
                {
                  offset: 0,
                  color: "#09132c",
                },
                {
                  offset: 1,
                  color: "#274d68",
                },
              ],
              // 延长作用域
              globalCoord: true,
            },
            // 盒子的阴影
            shadowColor: "rgb(58,115,192)",
            // 偏移
            shadowOffsetX: 5,
            shadowOffsetY: 7,
          },
        },
        region: [
          {
            name: "南海诸岛",
            itemStyle: {
              opacity: 0,
            },
          },
        ],
      },
      series: [
        // 配置地图相关的数据参数
        {
          type: "map",
          label: {
            normal: {
              // 显示文字
              show: true,
              textStyle: {
                color: "#fff",
              },
            },
            emphasis: {
              textStyle: {
                color: "red",//鼠标滑过字体颜色
              },
            },
          },
          // 图层
          zoom: 1.1,
          map: "china",
          itemStyle: {
            normal: {
              // 背景色
              backgroundColor: "rgb(147,235,248)",
              // 边框
              borderWidth: 1,
              // 区域颜色
              areaColor: {
                type: "radial",
                x: 0.5,
                y: 0.5,
                // 文档
                r: 0.8,
                colorStops: [
                  { offset: 0, color: "rgb(50,50,150)" },
                  { offset: 1, color: "rgb(90,158,162)" }, //每个省的地图背景色
                ],
                // 全局生效
                globalCoord: true,
              },
            },
            // 高亮效果
            emphasis: {
              areaColor: "reb(70,70,150)",//鼠标滑过背景颜色
              borderWidth: 0.1,
            },
          },
        },
      ],
    });
  },
  methods: {},
};
</script>

<style lang="scss" scoped>
.map-view {
  width: 683px;
  height: 420px;
}
#main {
    width: 683px;
    height: 420px;
  }
</style>

三、在需要的页面引入地图组件

 

标签:map,vue,color,地图,rgb,china,引入,echarts
From: https://www.cnblogs.com/anna001/p/17351146.html

相关文章

  • vue2源码-十四、computed和watch的区别
    computed和watch的区别computed和watch的相同点。底层都会创建一个watcher(用法的区别:computed定义的属性可以在模板中使用,watch不能在视图中使用)computed默认不会执行只有取值的时候才会执行内部会维护一个dirty属性,来控制依赖的值是否发生变化。默认计算属性需要同......
  • vue关于请求消息没问题但是还是进入catch块(已解决)
    第一次使用vue中的拦截器,一开始是在拦截器的逻辑代码上有问题(也有可能没问题),然后请求和响应都是没问题的,但是请求之后就是不跳转,然后发现是设置了拦截器的问题,折磨了下拦截器保证了代码能够顺利运行到resolve,但是发现即便是resolve后回到原本的代码中,代码还是运行到catch块中去。......
  • Vue关于beforeRouteEnter以及beforeRouteLeave函数的运用
    先上代码beforeRouteEnter:(to,from,next)=>{console.log("进入路由之前")next(vm=>{vm.getData();});},beforeRouteLeave:(to,from,next)=>{console.log("进入路由之后")next();},methods:{getData:f......
  • vue3+jointjs demo
    下面是使用Vue3和JointJS添加元素的示例代码:1.安装JointJS```terminalnpminstalljointjs--save```2.创建JointJS图形```javascriptimport{ref,onMounted}from'vue';import*asjointfrom'jointjs';exportdefault{setup(){constgraphC......
  • Echarts
    官网:https://echarts.apache.org/examples/zh/index.html#chart-type-bar1、Echarts中饼图的使用(附:formatter中{d}百分比位数修改) 例如:label:{position:'inside',formatter:"{b}:{c}({d}%)"},效果: 参考文献:https://blog......
  • vue全屏
    <template><div><imgsrc="../assets/fangda.png"@click="toggleFullscreen"/></div></template><script>exportdefault{methods:{toggleFullscreen(){if(document.fullscree......
  • Vue2和ElementUI编写的无限级菜单路由
    Vue2和ElementUI编写的无限级菜单路由文章转载自:www.javaman.cn<template><div><el-menu:default-active="$route.path"class="el-menu-vertical-demo":collapse="isCollapse"router><templatev-for="item......
  • Vue3 Vue3中其他的改变
    视频六、其他1.全局API的转移Vue2.x有许多全局API和配置。例如:注册全局组件、注册全局指令等。//注册全局组件Vue.component('MyButton',{data:()=>({count:0}),template:'<button@click="count++">Clicked{{count}}times.</button>......
  • Vue.js 目录
    Vue.js大致介绍Vue官网Vue.js搭建Vue开发环境(p4~p6)Vue.js模板语法Vue.js数据绑定Vue.jsel与data的两种写法Vue.js理解MVVMVue.js数据代理-回顾Object.defineProperty方法&数据代理理解Vue.js事件处理-事件的基本使用v-on传参Vue.js事件处理-事件修饰符Vue.js事......
  • Vue笔记汇总
    Vue3快速上手1.Vue3简介2020年9月18日,Vue.js发布3.0版本,代号:OnePiece(海贼王)耗时2年多、2600+次提交、30+个RFC、600+次PR、99位贡献者github上的tags地址:https://github.com/vuejs/vue-next/releases/tag/v3.0.02.Vue3带来了什么1.性能的提升打包大小减少41%初次......