使用echarts绘制中国地图与航班线路图

本文介绍了如何在Vue项目中安装并使用ECharts库,包括引入地图数据、设置地图样式以及添加路线数据,以实现中国地图的动态展示和线路的可视化效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在vue项目中实现:

1.安装echarts

npm i echarts

 2.使用echarts,这里需要中国地图的json数据,可以自行查找(或者私我)。

// echarts5版本,引入echarts的方式发生了改变,要使用以下方式引入

import * as echart from "echarts"

import {ref,onMounted} from "vue"

// 引入中国地图的json数据

import CHINA from "./assets/china.json";

let container=ref()

onMounted(() => {

  let myChart = echarts.init(container.value);

   // 注册地图

  echarts.registerMap("china", CHINA as any);

  myChart.setOption({

    geo: [

      {

        show: true,

        map: "china",

        roam: true,

        label: {

          show: true,

          color: "white",

        },

        itemStyle: {

          areaColor: {

            // 径向渐变

            type: "radial",

            x: 0.5,

            y: 0.5,

            r: 0.5,

            colorStops: [

              {

                offset: 0,

                color: "green", // 0% 处的颜色

              },

              {

                offset: 1,

                color: "#399036", // 100% 处的颜色

              },

            ],

          },

        },

        // 强调(鼠标放上去的省份位置)

        emphasis: {

          label: {

            fontSize: 16,

            color: "white",

          },

          itemStyle: {

            color: "green",

            opacity: 0.9,

          },

        },

      },

    ],

    series: [

      {

        // 用于带有起点和终点信息的线数据的绘制,主要用于地图上的航线,路线的可视化

        type: "lines",

        data: [

          {

            // coords是一个二维数组

            coords: [

              [116.405285, 39.904989],

              [112.549248, 37.857014],

            ],

          },

          {

            coords: [

              [111.670801, 40.818311],

              [121.472644, 31.231706],

            ],

          },

        ],

        lineStyle: {

          color: "white",

          opacity: 0.1,

          width: 2,

          type: [2, 2],

          curveness: 0.1,

        },

        // 特效

        effect: {

          show: true,

          period: 4,

           // 特效图形的标记,可以使用图片链接,或者"path://"+svg图标的矢量路径

          symbol:  "rect",

          symbolSize: 16,

          color: "skyblue",

        },

      },

    ],

  });

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值