首页 > 其他分享 >Echarts5之广东map

Echarts5之广东map

时间:2024-07-02 14:09:06浏览次数:13  
标签:map 广东 show echarts item Echarts5 import type id

效果图

示例图

Components

<template>
    <div id="bmap" ref="canvas" class="canvas" :style="{width: '100%;', height: canHeight+'px'}"></div>
</template>
<script setup lang="ts">
import { defineProps, computed, onMounted } from 'vue'
import { createPinia } from 'pinia'
import guangdong from '@/components/maps/map/json/province/guangdong.json'
import * as echarts from 'echarts/core';
import {
  TooltipComponent,
  type TooltipComponentOption,
  GeoComponent,
  type GeoComponentOption,
  LegendComponent,
  type LegendComponentOption,
  VisualMapComponent,
  type VisualMapComponentOption,
  GridComponent, 
  type GridComponentOption,
  MarkPointComponent,
  type MarkPointComponentOption,
  TitleComponent,
  type TitleComponentOption,
} from 'echarts/components';
import { LabelLayout } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';
import { MapChart, type MapSeriesOption
 } from 'echarts/charts';
import { useChartsStore } from '@/stores/charts';
import { BarChart, type BarSeriesOption, PictorialBarChart, PictorialBarSeriesOption } from 'echarts/charts';
const pinia = createPinia();
const chartStore = useChartsStore(pinia)
echarts.use([
  TooltipComponent,
  GeoComponent,
  LegendComponent,
  CanvasRenderer,
  LabelLayout,
  VisualMapComponent,
  MapChart,
  GridComponent,
  MarkPointComponent,
  LegendComponent,
  TitleComponent,
  BarChart,
  PictorialBarChart
]);

type EChartsOption = echarts.ComposeOption<
  | TooltipComponentOption
  | GeoComponentOption
  | LegendComponentOption
  | VisualMapComponentOption
  | MapSeriesOption
  | GridComponentOption
  | MarkPointComponentOption
  | LegendComponentOption
  | TitleComponentOption
  | BarSeriesOption
  | PictorialBarSeriesOption
>;
const props = defineProps({
    canvasHeight: {
        type:Number,
        default: 300
    },
    data: {
        type: Object,
        default: () => { } 
    }
})
let canHeight = computed(() => { return props.canvasHeight })

onMounted(() => {
    echarts.registerMap('guangdong', guangdong);
    var chartDom = document.getElementById('bmap')!;
    var myChart = echarts.init(chartDom);
    var option: EChartsOption;
    var barOption: EChartsOption;

    option = {
        title: {show: true, name: "广东地图"},
        color: chartStore.colors,
        grid: { show: true, left: "0", right: "0", bottom: "0", top: "0", borderColor: "transparent" },
        legend: { show: true},
        geo: {
            show: true,
            map: 'guangdong',
            roam: false,
            zoom: 1.2,
            nameMap: {'guangdong' : '广东'},
            label: { show: true, color: '#a4a896'},
            itemStyle: {
                areaColor: '#0000ff60',
                borderColor: '#fefefe',
                borderWidth: 2,
                borderType: 'dashed'
            },
            emphasis: {
                disabled: false,
                label: { show: true, color: '#ffffff', fontSize: 20,},
                itemStyle: {
                    areaColor: '#0e3c8b',
                    borderColor: '#2e74ea',
                    borderWidth: 4,
                    borderType: 'soild'
                },
            },
            select: {
                disabled: false,
                label: { show: true, color: '#fefefe', fontSize: 20},
                itemStyle: {
                    areaColor: '#0000ff',
                    borderColor: '#2e74ea',
                    borderWidth: 4,
                    borderType: 'soild'
                },
            },
            left: '10%',
            top: '10%',
        },
        tooltip: {
            show: true,
            position: 'right',
            formatter: (param) => {
                return param.value ?  [param.name+":", param.value].join('\n') : null
            },
            backgroundColor: '#a2c1f6',
            borderColor: '#0e3c8b',
            borderWidth: 2,
            textStyle: { 
                color: 'blue',
                fontSize: 18,
                fontWeight: 600
            }
        },
        series: [
            {
                type: 'map',
                map: 'guangdong',
                geoIndex: 0,
                selectedMode: 'multiple',
                data: props.data.map((m) => {
                    m['selected'] = true
                    return m
                })
            }
        ]
    };
    option && myChart.setOption(option);

    let mdata = [...props.data]   
    barOption = {
        xAxis: [],
        yAxis: [],
        grid: [],
        series: []
    }
    mdata.forEach((item, i) => {
        const coord = myChart.convertToPixel('geo', item.pos);
        barOption.xAxis.push({
            id: item.id + i,
            gridId: item.id + i,
            show: false,
            type: 'category',
            data: [item.name],
            z: 1
        })
        barOption.yAxis.push({
            id: item.id + i,
            gridId: item.id + i,
            show: false,
            type: 'value',
            z: 1
        })

        barOption.grid.push({
            id: item.id + i,
            width: 40 * 1,
            height: 70 * 1,
            left: coord[0] -20,
            top: coord[1] -80,
            z: 1
        })

        barOption.series.push({
            id: item.id + i,
            xAxisId: item.id + i,
            yAxisId: item.id + i,
            data: [item.value],
            type: 'pictorialBar',
            symbol: "path://M538.624 65.536c-156.16 0-293.376 126.464-293.376 281.6 0 144.384 290.304 490.496 290.304 490.496s300.544-340.992 300.544-490.496c0-155.648-140.8-281.6-297.472-281.6z m5.12 421.888c-73.216 0-132.608-58.368-132.608-130.048S471.04 227.328 543.744 227.328c73.216 0 132.608 58.368 132.608 130.048s-59.392 130.048-132.608 130.048z",
            symbolSize: 30,
            symbolRotate: 0
        })
        
    });
    barOption && myChart.setOption(barOption);    

})
</script>

<style scope></style>

Html

<section class="map">
    <GuangDongMap v-if="show" :canvasHeight="340" :data="mapData" />
    <section class="data-legend">
        <n-flex v-for="(item, i) in mapData" :key="i" class="flex-start">
            <n-icon :size="16" :color="chartStore.colors[i+1]"><LocationSharp /></n-icon> {{ item.name }}
        </n-flex>
    </section>
</section>

CSS

.map {
    background-color: #02082c;
    border-radius: 10px;
    border: 1px solid #0000ff;
    padding: 10px 0;
    position: relative;
}
.data-legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    color: #ffffff;
}

标签:map,广东,show,echarts,item,Echarts5,import,type,id
From: https://www.cnblogs.com/min77/p/18279769

相关文章

  • go语言之map取值
    packagemainimport("fmt")funcmain(){//定义一个maptemp_dict:=make(map[string]string)temp_dict["A"]="A__value"//1获取某一个key的值//1.1两个返回值r1_value,r1_exisit:=temp_dict["A"]......
  • Nginx(openresty) X-Forwarded-For $proxy_add_x_forwarded_for 多层代理 通过map分割
    1nginx配置#配置多层反向代理,配置如下proxy_passhttp://ip或者域名/;proxy_connect_timeout60;proxy_send_timeout60;proxy_read_timeout60;proxy_set_headerUpgrade$h......
  • .js.map文件泄露/Springboot信息泄露
    目录框架识别Webpack简述.js.map文件泄露利用Springboot 很多网站都使用的是现有的框架进行开发的,因此相当于很多目录和文件的路径都是开源可知的,因此我们就可以直接访问对应的路径,如果网站没有进行限制就有可能会导致敏感信息泄露框架识别可以根据页面的报错信息......
  • 免费在线数据可视化(PCA、t-SNE和UMAP)工具
    这是一款免费的数据可视化网页程序,上传数据即可进行可视化操作。可自定义数据类别属性(颜色、形状和尺寸),数据预处理操作,选择可视化方法(PCA、t-SNE和UMAP)即可进行可视化绘图,生成的图件能满足文章发表的格式,可保存为矢量化PDF,放入到Coreldraw、Ai等软件进行二次美化。URL:https://......
  • 45、k8s-数据存储-配置存储-secret-(用于存储配置信息的-比configMap安全)-密文存储
    作用:用于存储敏感信息、例如密码、密钥、证书等实验:创建secret、再将secret挂载到容器里去、使用容器查看secret存储的信息1、先使用base64对数据进行编码·echo-n'admin'|base64---------------------------YWRtaW4=---------------------------......
  • 44、k8s-数据存储-配置存储-configMap-(用于存储配置信息的)
    概念:ConfigMap是一种比较特殊的存储卷、它主要的作用是用来存储配置信息的其模板如下:1、创建配置卷的yaml文件:vimconfigmap.yaml-------------------------------------------------------apiVersion:v1kind:ConfigMapmetadata:name:configmapnamespace:devdat......
  • Java--Map集合
    Map映射(map)是存储键和值间关联(即,键值对)的对象。给定一个键,可以找到其值。键和值都是对象。键必须唯一,但是值可以重复。支持映射的接口接 口描 述Map将唯一键映射到值NavigableMap扩展SortedMap接口,以处理基于最接近匹配搜索原则的键/值对检索SortedMap......
  • 慢查询、pipline、发布订阅、 bitmap位图、 hyperloglog、geo、持久化
    【慢查询】1#1我们配置一个时间,如果查询时间超过了我们设置的时间,我们就认为这是一个慢查询2#2慢查询是一个先进先出的队列,固定长度,保存在内存中--->通过设置慢查询,以后超过我们设置时间的命令,就会放在这个队列中3#3后期我们通过查询这个队列,过滤出慢命令--》......
  • hadoop集群部署【二】YARN & MapReduce 的部署
    提前注意:请注意路径是否和我的相同,放置的位置不同,请修改标红处 HDFS部署HDFS介绍及部署http://t.csdnimg.cn/Q3H3Y部署说明HadoopHDFS分布式文件系统,我们会启动:NameNode进程作为管理节点DataNode进程作为工作节点SecondaryNamenode作为辅助同理,HadoopYARN分布式资源......
  • Qml接收QList<QVariantMap> 数据
    Q_PROPERTY(QList<QVariantMap>mediaSourceListREADgetMediaSourceListWRITEsetMediaSourceListNOTIFYsigMediaSourceListChanged)voidTESTCPP::setMediaSourceList(QList<QVariantMap>mediaSourceList){m_mediaSourceList.clear();#if1/......