一、地图下钻
1.效果
地图下钻和返回
2.关键代码
watch: {
"hnybRegion.countRegionName": {
handler() {
this.renderCharts();
},
deep: true,
},
},
methods: {
// 向上返回
backMain() {},
// 向下钻
goIntoMap(item) {
if (this.provinces.hasOwnProperty(item.name)) {
let obj = {
countRegionName: item.name,
countRegionCode: CodeObjMap[item.name],
};
this.$store.commit("changeHnybRegion", obj);
}
},
}
二、地图轮播
1.效果
地图轮播
2.关键代码
注意:地图下钻返回切换的时候要清除定时器,鼠标划入也要清除,页面销毁也要清除。
initHunanMap(mapData, mapName, visualMapVal) {
this.mapCharts = this.$echarts.getInstanceByDom(this.$refs.mapCharts);
if (this.mapCharts == null) {
this.mapCharts = this.$echarts.init(this.$refs.mapCharts);
}
this.$echarts.registerMap(mapName, this.provinces[mapName]);
let option = this.getMapEchartsOption(
mapName,
mapData,
formatterFunc,
visualMap
);
this.mapCharts.hideLoading();
this.mapCharts.off('click') //图表渲染前销毁点击事件
this.mapCharts.on("click", (params) => {
this.goIntoMap(params);
}); // 点击
this.mapCharts.setOption(option);
this.aniarrayArrays=mapData;
this.mapSwiper(mapData);
},
mapSwiper(mapData){
if(this.mapEchartsEmpty||this.mapEchartsError){
this.clearTooltip();
this.mapCharts.dispatchAction({
type:'hideTip'
})
}else{
this.faultByHourIndex=0;
this.setAnimation();
this.mouseAnimation();
}
},
setAnimation(){
if(this.faultByHourTime!=''){
clearInterval(this.faultByHourTime);
this.faultByHourTime='';
}
this.faultByHourTime = setInterval(()=>{
// 清除之前的高亮
if(this.faultByHourIndex){//不为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.faultByHourIndex-1
});
}else{//为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.aniarrayArrays.length-1
});
}
// 当前下标高亮
this.mapCharts.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: this.faultByHourIndex
});
// 当前下标浮窗
this.mapCharts.dispatchAction({
type:"showTip",
seriesIndex:0,
dataIndex:this.faultByHourIndex,
});
this.faultByHourIndex++;
if(this.faultByHourIndex>=this.aniarrayArrays.length){
this.faultByHourIndex = 0
}
},6000)
},
clearTooltip(){// 停止定时器,清除之前的高亮
if(this.faultByHourTime){
clearInterval(this.faultByHourTime);
this.faultByHourTime = '';
}
if(this.faultByHourIndex){//不为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.faultByHourIndex-1
});
}else{//为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.aniarrayArrays.length
});
}
this.faultByHourIndex = 0;
},
mouseAnimation() {
// 鼠标划入
this.mapCharts.on('mouseover', () => {
this.clearTooltip();
});
// 鼠标划出重新定时器开始
this.mapCharts.on('mouseout', () => {
this.setAnimation();
});
},
公共部分:字典:largeScreenDict.js
export const RegionCodeOption = [
{ value: "430000", name: "湖南省" },
{ value: "430100", name: "长沙市" },
{ value: "430200", name: "株洲市" },
{ value: "430300", name: "湘潭市" },
{ value: "430400", name: "衡阳市" },
{ value: "430500", name: "邵阳市" },
{ value: "430600", name: "岳阳市" },
{ value: "430700", name: "常德市" },
{ value: "430800", name: "张家界市" },
{ value: "430900", name: "益阳市" },
{ value: "431000", name: "郴州市" },
{ value: "431100", name: "永州市" },
{ value: "431200", name: "怀化市" },
{ value: "431300", name: "娄底市" },
{ value: "433100", name: "湘西土家族苗族自治州" },
]
export const RegionObjMap = {
"430000": "湖南省",
"430100": "长沙市",
"430200": "株洲市",
"430300": "湘潭市",
"430400": "衡阳市",
"430500": "邵阳市",
"430600": "岳阳市",
"430700": "常德市",
"430800": "张家界市",
"430900": "益阳市",
"431000": "郴州市",
"431100": "永州市",
"431200": "怀化市",
"431300": "娄底市",
"433100": "湘西土家族苗族自治州",
}
export const CodeObjMap = {
"湖南省": "430000",
"长沙市": "430100",
"株洲市": "430200",
"湘潭市": "430300",
"衡阳市": "430400",
"邵阳市": "430500",
"岳阳市": "430600",
"常德市": "430700",
"张家界市": "430800",
"益阳市": "430900",
"郴州市": "431000",
"永州市": "431100",
"怀化市": "431200",
"娄底市": "431300",
"湘西土家族苗族自治州": "433100",
}
export const ProvincesMap = {
湖南省: require("../json/hunan.json"),
长沙市: require("../json/changsha.json"),
株洲市: require("../json/zhuzhou.json"),
湘潭市: require("../json/xiangtang.json"),
常德市: require("../json/changde.json"),
郴州市: require("../json/chengzhou.json"),
衡阳市: require("../json/hengyang.json"),
怀化市: require("../json/huaihua.json"),
娄底市: require("../json/loudi.json"),
邵阳市: require("../json/shaoyang.json"),
益阳市: require("../json/yiyang.json"),
永州市: require("../json/yongzhou.json"),
岳阳市: require("../json/yueyang.json"),
张家界市: require("../json/zhangjiajie.json"),
湘西土家族苗族自治州: require("../json/xiangxi.json"),
}
公共部分:echartsOptions.js 可复用的echarts option.供各个大屏引用。
import { outMonthFormat } from "@/utils/util";
//地图
export function getMapEchartsOption(mapName, mapData, formatterFunc, visualMap) {
let option = {
tooltip: {
trigger: 'item',
triggerOn: "mousemove",
backgroundColor: "transparent",
extraCssText: 'box-shadow: none;z-index:9',
borderWidth: 0,
padding: 0,
// confine: true,
formatter: formatterFunc,
// position:'bottom'
position: function (point, params, dom, rect, size) {
var x = 0; // x坐标位置
var y = 0; // y坐标位置
// 当前鼠标位置
var pointX = point[0];
var pointY = point[1];
// 外层div大小
var viewWidth = size.viewSize[0];
var viewHeight = size.viewSize[1];
// 提示框大小
var boxWidth = size.contentSize[0];
var boxHeight = size.contentSize[1];
// console.log("-----",pointX,pointY, viewWidth, viewHeight, boxWidth, boxHeight)
if (pointY < boxHeight) {//--------------------超出上面了
if (pointY + boxHeight < viewHeight) {//下面放得下
return [point[0] - 20, point[1] - 20];
} else {下面放不下
return [pointX, 0];
}
} else if (pointY + boxHeight > viewHeight) {//-------------------超出下面了
return [pointX, viewHeight - boxHeight + 20];
}
return [point[0] - 20, point[1] - 20];
}
},
toolbox: {
show: false,
orient: "vertical",
left: "right",
top: "center",
feature: {
dataView: { readOnly: false },
restore: {},
saveAsImage: {},
},
},
visualMap: {
show: false,
min: visualMap['min'],
max: visualMap['max'],
text: ["High", "Low"],
realtime: false,
calculable: true,
inRange: {
color: visualMap['color'],
},
},
series: [
{
type: "map",
map: mapName,
data: mapData,
zoom: 1.2,
label: {
show: true,
color: "rgba(255, 255, 255, 1)",
fontSize: 10,
},
itemStyle: {
borderWidth: 1, //边际线大小
borderColor: "#1290FA", //边界线颜色
areaColor: "#17399F ", //默认区域颜色
},
emphasis: {
label: {
color: "#fff",
},
itemStyle: {
areaColor: "#35e2ff",
}
},
selectedMode: false,
// select: {// 地图选中区域样式
// label: {
// color: "rgba(255, 255, 255, 1)",// 选中区域的label(文字)样式
// },
// itemStyle: {
// areaColor: "#17399F",// 选中区域的默认样式
// },
// },
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: '40%',
// silent: true,
// invisible: mapData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '16px',
// }
// }
};
return option;
}
//倒置柱状图
export function getColumnBarEchartsOption(xData, yData, columnBarColor, unit) {
let option = {
tooltip: {
trigger: "axis",
extraCssText: "max-width:200px;white-space: normal; word-break: break-all;",
confine: true,
axisPointer: {
type: "shadow",
},
formatter: "{b}:{c}" + unit,
},
legend: {},
grid: {
top: "5%",
left: "1%",
right: "10%",
bottom: "5%",
containLabel: true,
},
xAxis: {
show: xData.length,
type: "value",
name: unit,
nameGap: 4,
nameTextStyle: { color: "rgba(255, 255, 255, 0.5)", padding: [0, 0, 0, 0] },
splitLine: { show: false },//修改背景线条样式
axisLine: { show: false, },
axisTick: { show: false, },
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: 'rgba(255, 255, 255, 0.2)',
}
},
axisLabel: {
color: 'rgba(255, 255, 255, 0.5)', //更改坐标轴文字颜色
fontSize: 12 //更改坐标轴文字大小
},
},
yAxis: {
show: xData.length,
type: "category",
inverse: true,
data: xData,
splitLine: { show: false },
axisTick: { show: false, },
axisLabel: {
margin: 8,
color: 'rgba(255, 255, 255, 0.5)', //更改坐标轴文字颜色
fontSize: 12, //更改坐标轴文字大小
formatter: function (params) {
var val = "";
if (params.length > 4) {
val = params.substr(0, 3) + "...";
return val;
} else {
return params;
}
},
},
},
series: [
{
type: "bar",
data: yData,
barWidth: 14,
itemStyle: {
borderRadius: 7,
color: columnBarColor
},
label: {
show: true,
position: 'right',
color: 'rgba(255, 255, 255, 0.5)',
},
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: yData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return option;
}
//横置柱状图
export function getRowBarEchartsOption(xData, yData, columnBarColor, xUnit, yUnit) {
let option = {
tooltip: {
trigger: "axis",
confine: true,
axisPointer: {
type: "shadow",
},
formatter: "{b} : {c}" + yUnit,
},
legend: {},
grid: {
top: "16%",
left: "2%",
right: "5%",
bottom: "5%",
containLabel: true,
},
xAxis: {
// show:xData.length,
type: "category",
name: xUnit,
nameGap: 4,
nameTextStyle: { color: "rgba(255, 255, 255, 0.5)", padding: [0, 0, 0, 0] },
data: xData,
splitLine: { show: false },
axisTick: { show: false },
axisLabel: {
interval: 0,
fontSize: 10,
color: 'rgba(255, 255, 255, 0.5)',
},
},
yAxis: {
// show:xData.length,
type: "value",
name: yUnit,
nameGap: 4,
nameTextStyle: { color: "rgba(255, 255, 255, 0.5)", padding: [0, 0, 8, -30] },
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: 'rgba(255, 255, 255, 0.2)',
}
},
axisLine: {
show: true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { show: false, },
axisLabel: {
color: 'rgba(255, 255, 255, 0.5)', //更改坐标轴文字颜色
fontSize: 12 //更改坐标轴文字大小
},
},
series: [
{
type: "bar",
data: yData,
barWidth: 14,
itemStyle: {
borderRadius: 7,
color: columnBarColor,
},
label: {
show: true,
position: 'top',
color: 'rgba(255, 255, 255, 0.5)',
},
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: yData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return option;
}
//横置两个柱子柱状图
export function getRowTwoBarEchartsOption(xData, series1, series2, columnBar1Color, columnBar2Color, xUnit, yUnit) {
let option = {
tooltip: {
trigger: "axis",
confine: true,
axisPointer: {
type: "shadow",
},
// formatter: "{b} : {c}"+yUnit,
},
legend: {
x: "center",
y: "top",
textStyle: {
color: "rgba(255, 255, 255, 0.5)",
},
},
grid: {
top: "20%",
left: "2%",
right: "5%",
bottom: "5%",
containLabel: true,
},
xAxis: {
// show:xData.length,
type: "category",
name: xUnit,
nameGap: 4,
nameTextStyle: { color: "rgba(255, 255, 255, 0.5)", padding: [0, 0, 0, 0] },
data: xData,
splitLine: { show: false },
axisTick: { show: false },
axisLabel: {
interval: 0,
fontSize: 10,
color: 'rgba(255, 255, 255, 0.5)',
},
},
yAxis: {
// show:xData.length,
type: "value",
name: yUnit,
nameGap: 4,
nameTextStyle: { color: "rgba(255, 255, 255, 0.5)", padding: [0, 0, 8, -30] },
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: 'rgba(255, 255, 255, 0.2)',
}
},
axisLine: {
show: true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { show: false, },
axisLabel: {
color: 'rgba(255, 255, 255, 0.5)', //更改坐标轴文字颜色
fontSize: 12 //更改坐标轴文字大小
},
},
series: [
{
type: "bar",
data: series1,
name: '有效',
barWidth: 14,
itemStyle: {
borderRadius: 7,
color: '#008dff',
},
label: {
show: true,
position: 'top',
color: 'rgba(255, 255, 255, 0.5)',
},
},
{
type: "bar",
data: series2,
name: '无效',
barWidth: 14,
itemStyle: {
borderRadius: 7,
color: columnBar2Color,
},
label: {
show: true,
position: 'top',
color: 'rgba(255, 255, 255, 0.5)',
},
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: yData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return option;
}
//饼图
export function getPieEchartsOption(data, title, subTitle, subColor) {
let options = {
tooltip: {
trigger: "item",
confine: true,
formatter: "{b} : {c} ({d}%)",
},
legend: {
show: !!data.length,
x: "right",
y: "center",
orient: "verical",
textStyle: {
color: "rgba(255, 255, 255, 0.5)",
},
},
grid: {
top: "1%",
left: "1%",
right: "1%",
bottom: "0%",
containLabel: false,
},
title: {
show: !!data.length,
text: title,
subtext: subTitle,
itemGap: 4,
left: '38%',
top: '40%',
textStyle: {
color: "rgba(255, 255, 255, 0.5)",
fontSize: 12,
fontWeight: 'bold',
},
subtextStyle: {
color: subColor,
fontSize: 12,
fontWeight: 'bold',
},
textAlign: 'center'
},
series: [
{
type: "pie",
radius: !!data.length ? ["50%", "70%"] : ["0%", "0%"],
center: ["40%", "50%"], // 中心位置。默认都是50%
avoidLabelOverlap: false,
label: {
show: false,
},
labelLine: {
show: false,
},
data: data,
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: data.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return options;
}
//折线图阴影图
export function getShadowLineEchartsOption(xData, yData, xAxisLabel) {
xData = outMonthFormat(xData);
let options = {
tooltip: {
trigger: "axis",
confine: true,
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: "shadow" // 默认为直线,可选为:"line" | "shadow"
}
},
grid: {
top: "12%",
left: "1%",
right: "5%",
bottom: "1%",
containLabel: true
},
xAxis: {
// show:!!xData.length,
type: 'category',
data: xData,
// name: unit,// 这个设置只在末尾添加单位
// boundaryGap: true,
// nameLocation: 'end',
// nameTextStyle: {
// padding: [0, 0, 0, 0] // 四个数字分别为上右下左与原位置距离
// },
// nameGap: 4,
axisLabel: {
formatter: "{value}" + xAxisLabel,
},
axisLine: { //x轴刻度线
"show": true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { "show": false },
},
yAxis: {
// show:!!xData.length,
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: 'rgba(255, 255, 255, 0.5)',
}
},
axisLine: { //y轴刻度线
"show": true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { //y轴刻度线
"show": false
},
},
series: [
{
data: yData,
type: 'line',
lineStyle: {
color: '#1290FA',
width: 1
},
itemStyle: {
color: 'rgba(255, 255, 255, 0.5)',
borderColor: '#1290FA',
borderWidth: 1
},
areaStyle: {
color: {
type: 'linear', x: 0, y: 0, x2: 0, y2: 1,
colorStops: [
{
offset: 0,
color: '#1290fa' // 0% 处的颜色
},
{
offset: 1,
color: 'rgba(127, 87, 39, 0)' //
}
],
global: false // 缺省为 false
}
}
}
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: yData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return options;
}
//单折线图图
export function getOneLineEchartsOption(xData, yData, xAxisLabel) {
xData = outMonthFormat(xData);
let options = {
tooltip: {
trigger: 'axis',
confine: true,
// formatter: function (params) {
// let showHtml = params[0].axisValue + '月'
// + "<br/>" + params[0].seriesName + ":" + params[0].data
// + "<br/>" + params[1].seriesName + ":" + params[1].data;
// return showHtml;
// }
},
grid: {
top: "15%",
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
// show:!!xData.length,
type: 'category',
data: xData,
// name: unit,// 这个设置只在末尾添加单位
// boundaryGap: true,
// nameLocation: 'end',
// nameTextStyle: {
// padding: [0, 0, 0, 0] // 四个数字分别为上右下左与原位置距离
// },
// nameGap: 4,
axisLabel: {
formatter: "{value}" + xAxisLabel,
},
axisLine: { //x轴刻度线
"show": true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { "show": false },
},
yAxis: {
// show:!!xData.length,
type: 'value',
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: 'rgba(255, 255, 255, 0.5)',
}
},
axisLine: { //y轴刻度线
"show": true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { //y轴刻度线
"show": false
},
},
series: [
{
// name:
type: 'line',
data: yData,
itemStyle: {
color: '#FDAD4D'
}
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: xData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return options;
}
//双折线图图
export function getTwoLineEchartsOption(xData, yData1, yData2, legendArr, unit) {
xData = outMonthFormat(xData);
let options = {
tooltip: {
trigger: 'axis',
confine: true,
// formatter: function (params) {
// let showHtml = params[0].axisValue + '月'
// + "<br/>" + params[0].seriesName + ":" + params[0].data
// + "<br/>" + params[1].seriesName + ":" + params[1].data;
// return showHtml;
// }
},
legend: {
// show:!!xData.length,
data: legendArr,
textStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
grid: {
top: "15%",
left: '3%',
right: '12%',
bottom: '3%',
containLabel: true
},
xAxis: {
// show:!!xData.length,
type: 'category',
data: xData,
name: unit,// 这个设置只在末尾添加单位
boundaryGap: true,
nameLocation: 'end',
nameTextStyle: {
padding: [0, 0, 0, 0] // 四个数字分别为上右下左与原位置距离
},
nameGap: 4,
axisLine: { //x轴刻度线
"show": true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { "show": false },
},
yAxis: {
// show:!!xData.length,
type: 'value',
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: 'rgba(255, 255, 255, 0.5)',
}
},
axisLine: { //y轴刻度线
"show": true,
lineStyle: {
color: 'rgba(255, 255, 255, 0.5)'
}
},
axisTick: { //y轴刻度线
"show": false
},
},
series: [
{
name: legendArr[0],
type: 'line',
data: yData1,
itemStyle: {
color: '#19BE6B'
}
},
{
name: legendArr[1],
type: 'line',
data: yData2,
itemStyle: {
color: '#FDAD4D'
}
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: xData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return options;
}
export function getPiePerEchartsOption(color, title,data, subTitle, subColor){
let options = {
animation: true, //控制动画示否开启
animationDuration: 6000,
animationEasing: "bounceOut", //缓动动画
animationThreshold: 8, //动画元素的阈值
title: {
text: title,
left: 'center',
top: 'bottom',
textStyle:{
color:'#fff',
fontSize: 12,
fontWeight:'normal'
}
},
graphic: [
{
//环形图中间添加文字
type: "text", //通过不同top值可以设置上下显示
left: "center",
top: "36%",
style: {
text: '60%',
textAlign: "center",
fill: "#fff", //文字的颜色
fontSize: 14,
lineHeight: 20,
},
},
],
visualMap: {
show: false,
},
grid:{
bottom:'5%',
containLabel:true
},
series: [
{
type: 'pie',
//环形显示饼状图,实际上显示的是50-80之间的部分
//上限不建议设置为100,echarts自带动画效果,设置为100动画效果很丑
radius: ['55%', '65%'],
center: ['50%', '43%'],
data: [
//itemSyle是单项的背景颜色设置。
{ value: 60, itemStyle: { color: color} },
{ value: 40, itemStyle: { color: '#0a233d' } },
],
label: {
//将视觉引导图关闭
show: false,
},
itemStyle:{
//设置的是每项之间的留白
// borderWidth:7,
// borderColor:'#fff'
},
// 初始化echarts的动画效果
animationType: 'scale',
animationEasing: 'elasticOut',
animationDelay: function (idx) {
return Math.random() * 200;
}
}
]
}
return options;
}
//医保职工环形图
export function chartsZGOption(data, title, subTitle, subColor) {
let options = {
tooltip: {
trigger: "item",
confine: true,
formatter: "{b} : {c} ({d}%)",
},
legend: {
show: false,
x: "center",
y: "center",
orient: "verical",
textStyle: {
color: "rgba(255, 255, 255, 0.5)",
},
},
grid: {
top: "0%",
left: "2%",
right: "1%",
bottom: "0%",
containLabel: true,
},
title: {
show: !!data.length,
text: title,
subtext: subTitle,
itemGap: 4,
left: '46%',
top: '40%',
textStyle: {
color: "rgba(255, 255, 255, 1)",
fontSize: 12,
fontWeight: 'bold',
},
subtextStyle: {
color: subColor,
fontSize: 12,
fontWeight: 'bold',
},
textAlign: 'center'
},
series: [
{
type: "pie",
radius: !!data.length ? ["50%", "70%"] : ["0%", "0%"],
center: ["50%", "50%"], // 中心位置。默认都是50%
avoidLabelOverlap: false,
label: {
show: false,
},
labelLine: {
show: false,
},
data: data,
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: 'middle',
// silent: true,
// invisible: data.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '14px'
// }
// }
};
return options;
}
补充:完整map.vue代码
<template>
<div class="card_item map" style="position:relative">
<div class="card_echarts" style="width:100%;height:100%;position:relative;">
<div ref="mapCharts" id="mapCharts" style="width:100%;height:100%;margin:0 auto;box-sizing: border-box;"></div>
<Loading v-show="mapEchartsLoading" class="backgroundContain"></Loading>
<div v-show="mapEchartsEmpty" class="requestEmpty">
<div class="requestEmptyText">当前数据为零</div>
</div>
<div v-show="mapEchartsError" class="requestError">
<i class="el-icon-warning-outline"></i>
<div class="text">加载失败</div>
</div>
</div>
<div class="head_list">
<div class="list_text">
<div class="list_tit"><span>{{ levelTit }}</span>本级业务经办量</div>
<div class="list_num">
<count-to :startVal="startVal" :endVal="endVal" :duration="numRollTime"></count-to><span class="unit">件</span>
</div>
</div>
</div>
<mapColor class="mapColor" :mapColorTitle="mapColorTitle" :mapDataFlag="mapDataFlag" />
</div>
</template>
<script>
import Loading from "@/components/LargeScreen/loading";
import mapColor from "@/components/hnybInfoMonitorPlat/mapColor/index.vue";
import {getRightCenterMapData} from "@/services/hnybInfoMonitorPlat";
import {
RegionCodeOption,
RegionObjMap,
CodeObjMap,
ProvincesMap,
} from "@/utils/largeScreenDict";
export default {
name: "centerMap",
props:['getNumber'],
components: { Loading, mapColor },
data() {
return {
mapCharts: null,
mapEchartsEmpty: false,
mapEchartsError: false,
mapEchartsLoading: false,
regionCodeOption: RegionCodeOption,
provinces: ProvincesMap,
mapColorTitle: "当日业务经办总量",
mapDataFlag: true,
timer:null,
faultByHourTime:'',
faultByHourIndex:0,
aniarrayArrays:[],
mapData:null,
//省本级业务经办量
startVal:0,
endVal:0,
numRollTime:2000,
levelTit:'省',
timer1:null
};
},
beforeDestroy() {
window.removeEventListener("resize", () => {
this.resizeCharts();
});
if(this.timer){
clearInterval(this.timer)
}
if(this.timer1){
clearInterval(this.timer1)
}
},
destroyed() {
this.clearTooltip();
this.mapCharts.off('mouseover');
this.mapCharts.off('mouseout');
},
activated(){
// this.renderCharts();
this.mapCharts && this.resizeCharts();
},
deactivated(){
// this.clearTooltip();
// this.mapCharts.off('mouseover');
// this.mapCharts.off('mouseout');
},
mounted() {
this.renderCharts();
window.addEventListener("resize", () => {
this.resizeCharts();
});
this.timer = setInterval(()=>{
this.renderCharts();
},15*60*1000)
},
computed: {
hnybRegion() {
return this.$store.state.hnybRegion;
},
},
watch: {
getNumber:{
handler(val) {
if(this.timer1){
clearInterval(this.timer1)
}
this.startVal = Number(this.getNumber.oldData);
this.endVal = Number(this.getNumber.oldData);
let data = parseInt(this.getNumber.newData - this.getNumber.oldData)
this.getNum(data,this.endVal,'startVal','endVal');
},
deep:true
},
"hnybRegion.countRegionName": {
handler() {
let codeName = this.hnybRegion.countRegionName;
this.levelTit = codeName.indexOf("省") !== -1 ? '省' : '市';
this.renderCharts();
},
deep: true,
},
},
methods: {
//获取随机数整数
getNum(sectionData,startVal,startProp,endProp){
//随机5000内的数字 相加等于 5000
var arr = new Array(300).fill(0)
for(var i=0;i<sectionData;i++){
var num = parseInt(Math.random()*300)
// var num = Number((Math.random()*10).toFixed(2))
arr[num] ++
}
// console.log(arr)
//从startVal开始 数组中每前2项相加 获得的 新数组
let sum = startVal;
let obj=[];
for (let j = 0; j < arr.length; j++) {
sum += arr[j];
obj.push(sum)
}
// console.log(obj)
//拆成奇数 跟 偶数 下标
let oddArr = []; // 存放奇数下标元素的数组
let evenArr = []; // 存放偶数下标元素的数组
for (let k = 0; k < obj.length; k++) {
if (k % 2 === 0) {
evenArr.push(obj[k]);
} else {
oddArr.push(obj[k]);
}
}
// console.log('奇', oddArr,'偶', evenArr)
let countNum=0
this.timer1 =setInterval((startProp,endProp)=>{
if(countNum >= 150){
clearInterval(this.timer1)
}else{
this[startProp] = evenArr[countNum];
this[endProp] = oddArr[countNum];
countNum++;
}
},4000,startProp,endProp);
},
resizeCharts() {
this.mapCharts.resize();
},
renderCharts() {
this.renderInitCharts();
this.getMapChartData();
},
renderInitCharts() {
this.mapEchartsEmpty = false;
this.mapEchartsError = false;
this.mapEchartsLoading = true;
if(this.mapCharts){
this.clearTooltip();
this.mapCharts.off('mouseover');
this.mapCharts.off('mouseout');
this.mapCharts.dispatchAction({
type:'hideTip'
})
}
},
getMapChartData() {
getRightCenterMapData(this.hnybRegion.countRegionCode).then((res) => {
if (res.code == 200) {
if(!!res.data && res.data.length>0){
this.handleMapChartData(res.data)
}
}else{
// this.mapEchartsEmpty=true;
this.initHunanMap([], this.hnybRegion.countRegionName);
}
this.mapEchartsLoading=false;
}).catch(()=>{
this.mapEchartsLoading=false;
// this.mapEchartsError=true;
this.initHunanMap([], this.hnybRegion.countRegionName);
})
},
// 二次处理后台接口返回数据
handleMapChartData(res){
let visualMapArr = []
let visualMapVal = null
let result = JSON.parse(JSON.stringify(res).replace(/area/g,'name').replace(/businessNum/g,'value'));
result.forEach((item,index)=>{
if(index<5){ //赋值TOP5
item.top=index+1
}
item.value = Number(item.value)
visualMapArr.push(item.value)
})
// 去重
visualMapArr=Array.from(new Set(visualMapArr));
// visualMap,自行拆分三份
if(visualMapArr.length>2){
const list = visualMapArr;
const threePartIndex = Math.round(list.length / 3);
const thirdPart = list.splice(-threePartIndex);
const secondPart = list.splice(-threePartIndex);
const firstPart = list;
visualMapVal={
min:Number(thirdPart[0]),
max:Number(secondPart[0]),
}
// console.log('111111',firstPart,secondPart,thirdPart)
}else{
visualMapVal={
min:0,
max:visualMapArr[visualMapArr.length-1],
}
}
// console.log('0visualMapVal',visualMapVal)
// console.log('result',result)
this.initHunanMap(result, this.hnybRegion.countRegionName,visualMapVal);
},
initHunanMap(mapData, mapName, visualMapVal) {
this.mapCharts = this.$echarts.getInstanceByDom(this.$refs.mapCharts);
if (this.mapCharts == null) {
this.mapCharts = this.$echarts.init(this.$refs.mapCharts);
}
this.$echarts.registerMap(mapName, this.provinces[mapName]);
let formatterFunc = function (params) {
if (!!params.data) {
const dotHtml2 = `<div style="padding:10px 10px 0 10px;width: 120px;height: 62px;border-radius: 4px;background:rgba(0, 0, 0, 0.75);">
<div style="height:50%;font-weight: 400;font-size: 14px;line-height:16px;color: #fff;">业务经办量</div>
<div style="height:50%;font-weight: 700;font-size: 18px;line-height: 16px;color: #f8b62d;">${params.data.value}<span style="font-weight: 400;font-size: 14px;color: #fdad4d;">件</span></div>
</div>`;
return dotHtml2;
} else {
return "";
}
};
let visualMap = {
min: visualMapVal?visualMapVal.min:1,
max: visualMapVal?visualMapVal.max:100,
color: ["#17399F", "#17399F", "#17399F"],
};
let option = this.getMapEchartsOption(
mapName,
mapData,
formatterFunc,
visualMap
);
this.mapCharts.hideLoading();
this.mapCharts.off('click') //图表渲染前销毁点击事件
this.mapCharts.on("click", (params) => {
this.goIntoMap(params);
}); // 点击
this.mapCharts.setOption(option);
this.aniarrayArrays=mapData;
this.mapSwiper(mapData);
},
mapSwiper(mapData){
if(this.mapEchartsEmpty||this.mapEchartsError){
this.clearTooltip();
this.mapCharts.dispatchAction({
type:'hideTip'
})
}else{
this.faultByHourIndex=0;
this.setAnimation();
this.mouseAnimation();
}
},
setAnimation(){
if(this.faultByHourTime!=''){
clearInterval(this.faultByHourTime);
this.faultByHourTime='';
}
this.faultByHourTime = setInterval(()=>{
// 清除之前的高亮
if(this.faultByHourIndex){//不为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.faultByHourIndex-1
});
}else{//为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.aniarrayArrays.length-1
});
}
// 当前下标高亮
this.mapCharts.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: this.faultByHourIndex
});
// 当前下标浮窗
this.mapCharts.dispatchAction({
type:"showTip",
seriesIndex:0,
dataIndex:this.faultByHourIndex,
});
this.faultByHourIndex++;
if(this.faultByHourIndex>=this.aniarrayArrays.length){
this.faultByHourIndex = 0
}
},6000)
},
clearTooltip(){// 停止定时器,清除之前的高亮
if(this.faultByHourTime){
clearInterval(this.faultByHourTime);
this.faultByHourTime = '';
}
if(this.faultByHourIndex){//不为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.faultByHourIndex-1
});
}else{//为0
this.mapCharts.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: this.aniarrayArrays.length
});
}
this.faultByHourIndex = 0;
},
mouseAnimation() {
// 鼠标划入
this.mapCharts.on('mouseover', () => {
this.clearTooltip();
});
// 鼠标划出重新定时器开始
this.mapCharts.on('mouseout', () => {
this.setAnimation();
});
},
// 向上返回
backMain() {},
// 向下钻
goIntoMap(item) {
if (this.provinces.hasOwnProperty(item.name)) {
let obj = {
countRegionName: item.name,
countRegionCode: CodeObjMap[item.name],
};
this.$store.commit("changeHnybRegion", obj);
}
},
getMapEchartsOption(
mapName,
mapData,
formatterFunc,
visualMap
) {
let option = {
tooltip: {
trigger: "item",
triggerOn: "mousemove",
backgroundColor: "transparent",
extraCssText: "box-shadow: none;z-index:9",
borderWidth: 0,
padding: 0,
formatter: formatterFunc,
position: function (point, params, dom, rect, size) {
var x = 0; // x坐标位置
var y = 0; // y坐标位置
// 当前鼠标位置
var pointX = point[0];
var pointY = point[1];
// 外层div大小
var viewWidth = size.viewSize[0];
var viewHeight = size.viewSize[1];
// 提示框大小
var boxWidth = size.contentSize[0];
var boxHeight = size.contentSize[1];
// console.log('0',rect)
if(pointX>viewWidth/2 || pointX==viewWidth/2){
return [pointX+30, pointY-boxHeight/2];
}else{
return [pointX-boxWidth-30, pointY-boxHeight/2];
}
}
},
toolbox: {
show: false,
orient: "vertical",
left: "right",
top: "center",
feature: {
dataView: { readOnly: false },
restore: {},
saveAsImage: {},
},
},
visualMap: {
show: false,
min: visualMap.min,
max: visualMap.max,
text: ["High", "Low"],
realtime: false,
calculable: true,
inRange: {
color:["#00B0FF", "#194CF3", "#17389E"],
},
seriesIndex:0
},
geo: [
{
id: "down",
map: mapName,
silent: true, //避免地图Hover
label: {
show: false,
color: "rgba(255, 255, 255, 1)",
fontSize: 10,
},
itemStyle: {
areaColor: "rgba(54, 77, 251, 0.5)",
borderColor: "rgba(59, 232, 253, 0.2)",
borderWidth: 2,
shadowColor: "#fff",
shadowBlur: 15,
opacity: 0.8,
},
emphasis: {
itemStyle: {
areaColor: "rgba(7, 19, 67, 1)",
borderColor: "rgba(59, 232, 253, 0.2)",
borderWidth: 1,
},
label: {
show: false,
color: "rgba(253, 173, 77, 1)",
},
},
},
{
id: "up",
map: mapName,
silent: true,//避免地图Hover
label: {
show: false,
color: "transparent",
fontSize: 10,
},
itemStyle: {
borderWidth: 1, //边际线大小
borderColor: "#1290FA", //边界线颜色
areaColor: "#17399F ", //默认区域颜色
},
emphasis: {
itemStyle: {
areaColor: "rgba(7, 19, 67, 1)",
borderColor: "rgba(59, 232, 253, 0.2)",
borderWidth: 1,
},
label: {
show: false,
color: "transparent",
},
},
},
],
series: [
// 用于地图中的图标
// {
// type: 'scatter',
// coordinateSystem: 'geo',
// // symbol: echartsOption.img,
// // symbolSize: [10, 10],
// // symbolOffset: [0, 8]
// zlevel: 2,
// rippleEffect: {
// brushType: "stroke",
// },
// label: {
// normal: {
// show: true,
// formatter: "{b}",
// position: "right",
// textStyle: {
// color: "#fff",
// fontSize: 10,
// },
// },
// emphasis:{
// textStyle:{
// color: "rgba(253, 173, 77, 1)",
// }
// }
// },
// symbolSize: 8,
// showEffectOn: "render",
// hoverAnimation: true,
// geoIndex:1,
// data: scatterOption,
// }
{
type: "map",
zlevel: 2,
map: mapName,
data: mapData,
label: {
show: true,
color: "rgba(255, 255, 255, 1)",
fontSize: 10,
formatter: function(param) {
let relabel = param.name
if(param.data&¶m.data.top){
relabel = param.name + ' (' + param.data.top + ')'
}
return relabel+'\n{b|}';
},
rich: {
b: {
backgroundColor: {
image: require('@/assets/hnybInfoMonitorPlat/right/centerNormal.png')
},
height: 18
},
}
},
itemStyle: {
borderWidth: 1, //边际线大小
borderColor: "#1290FA", //边界线颜色
areaColor: "#17399F ", //默认区域颜色
},
emphasis: {
label: {
show: true,
color: "rgba(253, 173, 77, 1)",
fontSize: 10,
formatter: function(param) {
let relabel = param.name
if(param.data&¶m.data.top){
relabel = param.name + ' (' + param.data.top + ')'
}
return relabel+'\n{b|}';
},
rich: {
b: {
backgroundColor: {
image: require('@/assets/hnybInfoMonitorPlat/right/centerEmphasis.png')
},
height: 18
},
}
},
itemStyle: {
areaColor: "rgba(7, 19, 67, 1)",
},
},
selectedMode: false,
// select: {// 地图选中区域样式
// label: {
// color: "rgba(255, 255, 255, 1)",// 选中区域的label(文字)样式
// },
// itemStyle: {
// areaColor: "#17399F",// 选中区域的默认样式
// },
// },
},
],
// graphic: {
// type: 'text',
// left: 'center',
// top: '40%',
// silent: true,
// invisible: mapData.length,
// style: {
// fill: 'rgba(255, 255, 255, 0.5)',
// fontWeight: 'bold',
// text: '暂无数据',
// fontSize: '16px',
// }
// }
};
return option;
},
},
};
</script>
<style type="text/css" lang="less" scoped="scoped">
.card_item.map {
width: 100%;
height: calc(100% - 100px);
display: block;
.back {
position: absolute;
top: 0px;
z-index: 999;
.buttonBack {
width: 70px;
height: 32px;
background: #234784;
border: 0;
color: #fff;
cursor: pointer;
}
.buttonBack:hover {
color: #35e2ff;
border: 1px solid #35e2ff;
}
span {
color: #fff;
font-size: 13px;
}
}
.mapColor {
position: absolute;
bottom: 0;
left: 20px;
}
.head_list {
position: absolute;
bottom: 100px;
left: 20px;
padding: 10px;
background-size: 100% 100%;
display: flex;
align-items: center;
// width: calc(50% - 5px);
border-radius: 4px;
background: rgba(69, 140, 201, 0.1);
.list_img {
// width: 44px;
height: 100%;
margin-right: 10px;
img {
width: 100%;
height: 100%;
}
}
.list_text {
.list_tit {
margin-bottom: 5px;
font-size: 14px;
color: #fff;
}
.list_num {
color: #fdad4d;
font-size: 20px;
.unit {
font-size: 14px;
}
}
}
}
}
.requestEmpty {
// display: none;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 999;
.requestEmptyText {
font-size: 14px;
color: #a6e1ff;
background: rgba(2, 9, 25, 0.6);
box-shadow: 0 2px 8px 0 rgb(0 0 0 /15%);
border-radius: 4px;
padding: 10px;
}
}
.requestError {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: rgba(2, 9, 25, 0.6);
z-index: 999;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.el-icon-warning-outline {
font-size: 34px;
color: #a6e1ff;
}
.text {
padding: 10px;
font-size: 14px;
color: #a6e1ff;
}
}
</style>