推荐一个基于Echarts实现的各种图表集:echarts图表集
1、获取街道和乡镇的数据
通过 阿里旗下的高德地图提供的api ,可以获取到中国各个省份/区级/县级的json数据,但是区级和县级,并没有包含街道和乡镇的数据。这里获取乡镇的数据是参考的他人的博客:导出乡镇、街道的地图geoJson数据_乡镇json_117jf的博客-CSDN博客
2、代码实现
<!-- 中间地图区域部分 -->
<template>
<div
class="zhongshanChart"
ref="charts1"
style="width: 700px; height: 700px"
></div>
</template>
<script>
import geoJson from "../../assets/areajson/zhongshan.json";
import { defineComponent, ref, onMounted } from "vue";
import * as echarts from "echarts";
export default defineComponent({
name: "zhongshangeo",
setup(props,cxt) {
let charts1 = ref(null);
let myEchart;
onMounted(() => {
myEchart = echarts.init(charts1.value);
initCharts();
});
function initCharts() {
let data = [];
let series = [];
series.push(
//设置poi点
{
type: "scatter",
coordinateSystem: "geo",
zlevel: 2,
rippleEffect: {
period: 4,
brushType: "stroke",
scale: 4,
},
label: {
show: true,
color: "#fff",
},
symbol: "pin", //定位图标样式
symbolSize: 40,
//点的名称和经纬度
data: [
{
value: [113.30545585806637, 22.714065986803993],
//单独修改圆环上的文字
label: {
formatter: "2", //圆环显示文字
},
itemStyle: {
color: "#fe2321",
},
},
{
name: "东升镇",
value: [113.30545585806637, 22.613065986803993],
label: {
formatter: "2", //圆环显示文字
},
itemStyle: {
color: "#fe2321",
},
},
{
name: "南区",
value: [113.34030985842813, 22.41766955088383],
label: {
formatter: "4", //圆环显示文字
},
itemStyle: {
color: "#fe2321",
},
},
{
name: "南区",
value: [113.35103885834923, 22.452021485741258],
label: {
formatter: "5", //圆环显示文字
},
itemStyle: {
color: "#fe2321",
},
},
{
name: "五桂山",
value: [113.44738185833575, 22.392456252206048],
label: {
formatter: "6", //圆环显示文字
},
itemStyle: {
color: "#fea200",
},
},
{
name: "五桂山",
value: [113.42448185833575, 22.422456252206048],
label: {
formatter: "6", //圆环显示文字
},
itemStyle: {
color: "#fea200",
},
},
],
},
{
type: "map",
geoIndex: 0,
//设置data是为了给地图不同区域设置颜色
data: [
{ name: "古镇镇", value: 1001 },
{ name: "小榄镇", value: 10001 },
{ name: "黄圃镇", value: 10001 },
{ name: "东凤镇", value: 101 },
{ name: "南头镇", value: 101 },
{ name: "横栏镇", value: 101 },
{ name: "东升镇", value: 101 },
{ name: "阜沙镇", value: 1001 },
{ name: "三角镇", value: 10001 },
{ name: "民众镇", value: 10001 },
{ name: "港口镇", value: 101 },
{
name: "西区",
value: 1001,
},
{ name: "沙溪镇", value: 1001 },
{ name: "大涌镇", value: 101 },
{ name: "南区", value: 1001 },
{ name: "东区", value: 101 },
{ name: "火炬开发区", value: 10001 },
{ name: "板芙镇", value: 10001 },
{ name: "五桂山", value: 1001 },
{ name: "南朗镇", value: 10001 },
{ name: "三乡镇", value: 101 },
{ name: "神湾镇", value: 1001 },
{ name: "坦洲镇", value: 1001 },
{ name: "石岐区", value: 1001 },
],
}
);
echarts.registerMap("zhouShan", geoJson);
var option = {
textStyle: {
color: "white",
},
visualMap: {
min: 0,
max: 100000,
left: 26,
bottom: 40,
showLabel: !0,
text: ["高", "低"],
// 对应 type=map, geoIndex=0 系列中value的值,通过值匹配颜色
pieces: [
{
gt: 10000,
label: "> 10000",
color: "#7faff6",
},
{
gte: 1000,
lte: 10000,
label: "1000 - 10000",
color: "#b3e6ee",
},
{
gte: 100,
lt: 1000,
label: "100 - 1000",
color: "#517ff4",
},
{
gt: 10,
lt: 100,
label: "10 - 100",
color: "#7faff6",
},
],
show: false,
},
geo: {
aspectScale: 1.3,
map: "zhouShan", //需要和echarts.registerMap('变量名')变量名一致
geoIndex: 1,
//图形上的文本标签
label: {
normal: {
show: true,
color: "#fff",
},
emphasis: {
show: true,
color: "#000",
},
},
top: 10,
roam: true, //是否允许缩放
layoutCenter: ["50%", "45%"], //地图位置
layoutSize: "105%",
//地图区域的多边形 图形样式
itemStyle: {
// normal: {
borderColor: "#8292fd", //省市边界线
borderWidth: 1, //边界宽度
// },
},
},
series: series,
};
myEchart.setOption(option);
myEchart.on('click','series.scatter',(params)=>{
// 点击poi点显示侧边栏组件 ---- 触发自定义事件
cxt.emit('showRight',true)
})
}
return {
charts1,
};
},
});
</script>
原文地址:https://blog.csdn.net/m0_73334325/article/details/131327895
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_8733.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。