<!-- 饼图 -->
<template>
<el-card>
<template #header> 地级市分类图 </template>
<div :id="id" :class="className" :style="{ height, width }"></div>
</el-card>
</template>
<script setup lang="ts">
import * as echarts from "echarts";
import mapGDjson from "@/views/dashboard/components/gd.json";
const props = defineProps({
id: {
type: String,
default: "pieChart",
},
className: {
type: String,
default: "",
},
width: {
type: String,
default: "200px",
required: true,
},
height: {
type: String,
default: "200px",
required: true,
},
});
const options = {
backgroundColor: "#fff",
title: {
text: "广东地图",
sublink:
"http://zh.wikipedia.org/wiki/%E9%A6%99%E6%B8%AF%E8%A1%8C%E6%94%BF%E5%8D%80%E5%8A%83#cite_note-12",
},
tooltip: {
trigger: "item",
formatter: "{b}<br/>{c} (p / km2)",
},
toolbox: {
},
series: [
{
name: "广东地图",
type: "map",
map: "map_area",
center: [114.085947, 22.547],
zoom: 10,
label: {
show: true,
},
itemStyle: {
normal: {
areaColor: "#b5b8ba",
borderColor: "#ffffff",
borderWidth: 2,
},
emphasis: {
areaColor: "#45ad00",
},
},
data: [
{
name: "福田区",
adcode: 440304,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "罗湖区",
adcode: 440303,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "南山区",
adcode: 440305,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "宝安区",
adcode: 440306,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "龙岗区",
adcode: 440307,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "盐田区",
adcode: 440308,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "龙华区",
adcode: 440309,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "坪山区",
adcode: 440310,
itemStyle: { normal: { areaColor: "#409eff" } },
},
{
name: "光明区",
adcode: 440311,
itemStyle: { normal: { areaColor: "#409eff" } },
},
],
nameMap: {
},
},
],
};
const chart = ref<any>("");
onMounted(() => {
chart.value = markRaw(
echarts.init(document.getElementById(props.id) as HTMLDivElement)
);
echarts.registerMap("map_area", mapGDjson);
chart.value.setOption(options);
window.addEventListener("resize", () => {
chart.value.resize();
});
});
onActivated(() => {
if (chart.value) {
chart.value.resize();
}
});
</script>
**
gd.json数据:(由于太多,就不粘贴进来了)
https: