Browse Source

fix: 更换echart 图表

feature-v1.0.0
ruancuihong 1 month ago
parent
commit
da96825a53
  1. 1
      package.json
  2. 134
      src/views/Main/DailyPatrolCard/index.vue
  3. 155
      src/views/Main/ProjectCountCard/index.vue
  4. 298
      src/views/Main/RiskInspectionCard/index.vue
  5. 5262
      yarn.lock

1
package.json

@ -21,6 +21,7 @@
"axios": "1.2.0",
"crypto-js": "4.1.1",
"echarts": "5.3.3",
"echarts-liquidfill": "^3.1.0",
"element-plus": "2.3.5",
"js-base64": "3.7.4",
"leader-line-vue": "^2.1.1",

134
src/views/Main/DailyPatrolCard/index.vue

@ -14,10 +14,10 @@
</template>
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from "vue";
import * as echarts from "echarts";
import { ref, onMounted, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';
defineOptions({
name: "DailyPatrolCard",
name: 'DailyPatrolCard'
});
let chart: echarts.ECharts | undefined;
const chartRef = ref();
@ -26,49 +26,133 @@ const handleResize = () => {
};
onMounted(() => {
chart = echarts.init(chartRef.value);
const pieName = ['一般', '重大', '较大', '紧急'];
const pieValue = [545, 21, 300, 64];
let count: any = 0;
const pieData: any = [];
for (var i = 0; i < pieName.length; i++) {
pieData.push({
name: pieName[i],
value: pieValue[i]
});
count += pieValue[i];
}
const legendStyle = {
type: 'scroll',
// orient: 'vertical',
// height: '95%',
width: '50%',
left: '50%',
textAlign: 'left',
align: 'left',
icon: 'circle', //
itemWidth: 10,
itemHeight: 10,
itemGap: 44, // 44
formatter: function (name: any) {
for (var i = 0; i < pieName.length; i++) {
if (name == pieData[i].name) {
return '{name|' + name + '}{rate|' + pieValue[i] + '}';
}
}
},
textStyle: {
rich: {
name: {
fontSize: 16,
fontWeight: 400,
width: 60,
height: 24,
padding: [0, 0, 0, 5],
color: 'rgba(0, 0, 0, 0.55)'
},
rate: {
fontSize: 18,
fontWeight: 'bold',
fontFamily: 'Microsoft YaHei',
height: 24,
width: 30,
padding: [60, 0, 0, -60],
color: 'rgba(0, 0, 0, 0.9)'
}
}
}
};
// Chart options
const option = {
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b}: {c} ({d}%)",
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
title: {
text: count,
subtext: '待处理问题',
x: '10%',
y: '34%',
align: 'center',
textStyle: {
color: 'rgba(0, 0, 0, 0.9)',
fontSize: 32,
lineHeight: 32, // 39
fontWeight: 'bold',
fontFamily: 'DIN'
},
subtextStyle: {
color: 'rgba(0, 0, 0, 0.6)',
fontSize: 14,
fontWeight: 500,
lineHeight: 2, // 24
padding: [-20, 0, 0, 0],
fontFamily: 'PingFang SC'
}
},
color: ["#4285F4", "#FF9F40", "#FFCD56", "#FF6384"],
color: ['#4293F4', '#FFDD77', '#FF9A23', '#F26161'],
legend: [
{
top: '15%',
//
data: pieName.slice(0, 2),
...legendStyle
},
{
top: '55%',
//
data: pieName.slice(2, 4),
...legendStyle
}
],
series: [
{
name: "问题类型",
type: "pie",
radius: ["50%", "70%"],
name: '问题类型',
type: 'pie',
radius: ['75%', '95%'],
center: ['20%', '50%'],
avoidLabelOverlap: false,
label: {
show: false,
show: false
},
emphasis: {
label: {
show: false,
},
show: false
}
},
labelLine: {
show: false,
show: false
},
data: [
{ value: 545, name: "一般" },
{ value: 21, name: "重大" },
{ value: 300, name: "较大" },
{ value: 64, name: "紧急" },
],
},
],
data: pieData
}
]
};
// Set options and render chart
chart.setOption(option);
window.addEventListener("resize", handleResize);
window.addEventListener('resize', handleResize);
});
onBeforeUnmount(() => {
chart?.dispose();
window.removeEventListener("resize", handleResize);
window.removeEventListener('resize', handleResize);
});
</script>
@ -98,7 +182,7 @@ onBeforeUnmount(() => {
line-height: 22px;
letter-spacing: 0px;
font-variation-settings: "opsz" auto;
font-variation-settings: 'opsz' auto;
color: rgba(0, 0, 0, 0.55);
span {
font-family: DIN;
@ -107,7 +191,7 @@ onBeforeUnmount(() => {
line-height: 22px;
letter-spacing: 0px;
font-variation-settings: "opsz" auto;
font-variation-settings: 'opsz' auto;
color: #28ce8e;
}
}

155
src/views/Main/ProjectCountCard/index.vue

@ -6,10 +6,10 @@
</template>
<script setup lang="ts">
import { onMounted, onBeforeUnmount, ref } from "vue";
import * as echarts from "echarts";
import { onMounted, onBeforeUnmount, ref } from 'vue';
import * as echarts from 'echarts';
defineOptions({
name: "ProjectCountCard",
name: 'ProjectCountCard'
});
const chartRef = ref();
let chart: echarts.ECharts | undefined;
@ -21,95 +21,158 @@ onMounted(() => {
chart = echarts.init(chartRef.value);
// Total count calculation
const reservoirCount = 5454;
const sluiceCount = 5454;
const damCount = 5454;
const reservoirCount = 544;
const sluiceCount = 454;
const damCount = 154;
const totalCount = 406; // Hard-coded total value shown in the center
const legendName = ['水库', '水闸', '堤防'];
const legendValue = [reservoirCount, sluiceCount, damCount];
const unit = ['座', '座', '段'];
const pieData: any = [];
for (var i = 0; i < legendName.length; i++) {
pieData.push({
name: legendName[i],
value: legendValue[i],
unit: unit[i]
});
}
// Chart options
const option = {
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b}: {c}",
trigger: 'item',
formatter: '{a} <br/>{b}: {c}'
},
legend: {
type: 'scroll',
orient: 'vertical',
height: '95%',
right: '8%',
top: '20%',
icon: 'circle', //
itemWidth: 10,
itemHeight: 10,
itemGap: 16,
data: legendName,
formatter: function (name: any) {
for (var i = 0; i < legendName.length; i++) {
if (name == pieData[i].name) {
return '{name|' + name + '}{rate|' + legendValue[i] + '}{unit|' + unit[i] + '}';
}
}
},
textStyle: {
rich: {
name: {
fontSize: 16,
fontWeight: 400,
height: 24,
padding: [0, 0, 0, 5],
color: 'rgba(0, 0, 0, 0.55)'
},
rate: {
fontSize: 18,
fontWeight: 500,
fontFamily: 'Microsoft YaHei',
height: 24,
padding: [48, 0, 0, -60],
color: 'rgba(0, 0, 0, 0.9)'
},
unit: {
fontSize: 16,
fontWeight: 500,
fontFamily: 'Microsoft YaHei',
height: 24,
padding: [48, 0, 0, 9],
// align: 'right',
color: 'rgba(0, 0, 0, 0.9)'
}
}
}
},
series: [
{
name: "工程数量",
type: "pie",
radius: ["40%", "70%"],
center: ["30%", "55%"],
startAngle: 90,
name: '工程数量',
type: 'pie',
roseType: 'area',
radius: ['40%', '70%'],
center: ['30%', '55%'],
startAngle: 270,
clockwise: false, // Set to counter-clockwise to match design
z: 10,
itemStyle: {
borderRadius: 0,
borderWidth: 1,
borderColor: "#fff",
borderWidth: 0,
borderColor: '#fff'
},
label: {
show: false,
show: false
},
data: [
{
value: reservoirCount,
name: "水库",
itemStyle: { color: "#4285F4" },
name: '水库',
itemStyle: { color: '#4293F4' }
},
{
value: sluiceCount,
name: "水闸",
itemStyle: { color: "#20C997" },
name: '水闸',
itemStyle: { color: '#30DFBA' }
},
{
value: damCount,
name: "堰坝",
itemStyle: { color: "#FF6384" },
},
],
name: '堤防',
itemStyle: { color: '#FF755B' }
}
]
},
{
name: "总数",
type: "pie",
radius: ["0", "30%"],
center: ["30%", "55%"],
name: '总数',
type: 'pie',
radius: ['0', '30%'],
center: ['30%', '55%'],
z: 0,
itemStyle: {
color: "#fff",
borderWidth: 1,
borderColor: "#eee",
color: 'transparent',
borderWidth: 0,
borderColor: '#eee'
},
label: {
position: "center",
position: 'center',
formatter: function () {
return ["{total|" + totalCount + "}", "{label|总数}"].join("\n");
return ['{total|' + totalCount + '}', '{label|总数}'].join('\n');
},
rich: {
total: {
color: "#333",
fontSize: 24,
fontWeight: "bold",
lineHeight: 30,
color: '#000',
fontSize: 28,
fontWeight: 'bold',
fontFamily: 'DIN',
lineHeight: 34
},
label: {
color: "#999",
color: 'rgba(0, 0, 0, 0.6)',
fontSize: 14,
lineHeight: 20,
},
},
lineHeight: 18,
fontFamily: 'Source Han Sans'
}
}
},
data: [{ value: 1, name: "总数" }],
},
],
data: [{ value: 1, name: '总数' }]
}
]
};
// Set options and render chart
chart.setOption(option);
window.addEventListener("resize", handleResize);
window.addEventListener('resize', handleResize);
});
onBeforeUnmount(() => {
chart?.dispose();
window.removeEventListener("resize", handleResize);
window.removeEventListener('resize', handleResize);
});
</script>

298
src/views/Main/RiskInspectionCard/index.vue

@ -15,10 +15,12 @@
</template>
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from "vue";
import * as echarts from "echarts";
import { ref, onMounted, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';
import 'echarts-liquidfill';
import 'echarts-liquidfill/src/liquidFill.js';
defineOptions({
name: "RiskInspectionCard",
name: 'RiskInspectionCard'
});
const problemEchartRef = ref();
const questEchartRef = ref();
@ -31,57 +33,165 @@ const handleResize = () => {
onMounted(() => {
leftChart = echarts.init(problemEchartRef.value);
const color = ['#FFBC37', '#429BF4'];
const dataStyle = {
normal: {
label: {
show: false
},
labelLine: {
show: false
},
shadowBlur: 40,
borderWidth: 10,
shadowColor: 'rgba(0, 0, 0, 0)' //
}
};
const placeHolderStyle = {
normal: {
color: 'rgba(255, 255, 255, 0.4)',
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: 'rgba(255, 255, 255, 0.4)'
},
tooltip: {
show: false
}
};
const legendName = ['数量', '问题数'];
const pieValue = [98, 56];
var pieData: any = [];
for (var i = 0; i < legendName.length; i++) {
pieData.push({
name: legendName[i],
value: pieValue[i]
});
}
// Chart options for the left side (nested pie)
const leftOption = {
tooltip: {
trigger: "item",
formatter: "{b}: {c}",
trigger: 'item',
formatter: '{b}: {c}'
},
color: ['#FFBC37', '#FFBC37'],
title: {
text: pieValue[0],
subtext: '工程总数',
x: 'center',
y: '20%',
textStyle: {
color: 'rgba(0, 0, 0, 0.9)',
fontSize: 32,
lineHeight: 32, // 39
fontWeight: 'bold',
fontFamily: 'DIN'
},
subtextStyle: {
color: 'rgba(0, 0, 0, 0.6)',
fontSize: 14,
fontWeight: 500,
lineHeight: 2, // 24
padding: [-20, 0, 0, 0],
fontFamily: 'PingFang SC'
}
},
legend: {
show: true,
// orient: 'vertical',
// x: '50%',
icon: 'circle',
top: 'bottom',
itemGap: 10, // 16
itemWidth: 8,
itemHeight: 8,
width: '100%',
textStyle: {
rich: {
name: {
fontSize: 14,
height: 25,
padding: [0, 8, 0, 5],
color: 'rgba(0, 0, 0, 0.55)'
},
rate: {
fontSize: 16,
fontWeight: 500,
height: 35,
color: 'rgba(0, 0, 0, 0.9)'
}
}
},
data: legendName,
formatter: function (name: any) {
for (var i = 0; i < legendName.length; i++) {
if (name == pieData[i].name) {
return '{name|' + name + '}{rate|' + pieValue[i] + '}';
}
}
}
},
color: ["#FFCD56", "#4285F4"],
series: [
{
type: "pie",
radius: ["65%", "90%"],
avoidLabelOverlap: false,
name: '数量',
type: 'pie',
clockWise: false,
radius: ['74%', '82%'],
center: ['50%', '40%'],
itemStyle: dataStyle,
hoverAnimation: false,
label: {
show: false,
position: "center",
},
emphasis: {
label: {
show: false,
},
},
labelLine: {
show: false,
borderRadius: '10'
},
color: color[0],
data: [
{ value: 98, name: "工程总数", itemStyle: { color: "#FFCD56" } },
{ value: 0, name: "", itemStyle: { color: "transparent" } },
],
{
//
value: pieValue[1],
name: '',
tooltip: {
show: false
},
itemStyle: placeHolderStyle
},
{
value: pieValue[0],
name: '数量'
}
]
},
{
type: "pie",
radius: ["40%", "60%"],
avoidLabelOverlap: false,
label: {
show: false,
position: "center",
},
emphasis: {
label: {
show: false,
},
},
labelLine: {
show: false,
},
name: '问题数',
type: 'pie',
radius: ['54%', '62%'],
center: ['50%', '40%'],
clockWise: false,
itemStyle: dataStyle,
hoverAnimation: false,
color: color[1],
data: [
{ value: 56, name: "问题数", itemStyle: { color: "#4285F4" } },
{ value: 42, name: "", itemStyle: { color: "transparent" } },
],
},
],
{
//
value: pieValue[0],
name: '',
tooltip: {
show: false
},
itemStyle: placeHolderStyle
},
{
value: pieValue[1],
name: '问题数'
}
]
}
]
};
// Set options and render left chart
@ -93,55 +203,99 @@ onMounted(() => {
const rightOption = {
series: [
{
type: "liquidFill",
radius: "80%",
data: [0.165],
type: 'liquidFill',
radius: '30%',
z: 4,
center: ['50%', '50%'],
amplitude: 5,
data: [0.5],
itemStyle: {
normal: {
color: '#28CE8E',
label: {
show: false
}
}
},
backgroundStyle: {
borderWidth: 0,
color: 'transparent'
},
label: {
normal: {
textStyle: {
fontSize: 35,
fontWeight: "bold",
color: "#000",
},
position: ["50%", "45%"],
formatter: function () {
return "16.5%";
},
},
formatter: ''
}
},
outline: {
show: true,
borderDistance: 0,
itemStyle: {
borderWidth: 1,
borderColor: "#20C997",
borderWidth: 0
},
},
color: ["#20C997"],
backgroundStyle: {
color: "rgba(32, 201, 151, 0.1)",
},
borderDistance: 0
}
},
{
name: legendName[0],
type: 'pie',
z: 1,
radius: ['0%', '31%'],
center: ['50%', '50%'],
hoverAnimation: false,
itemStyle: {
opacity: 0.7,
},
emphasis: {
itemStyle: {
opacity: 0.9,
},
normal: {
label: {
show: false
}
}
},
data: [
{
value: 1,
itemStyle: {
normal: {
color: 'rgba(255, 255, 255, 1)'
}
}
}
]
},
],
{
name: legendName[1],
type: 'pie',
z: 1,
radius: ['0%', '31%'],
center: ['50%', '50%'],
hoverAnimation: false,
itemStyle: {
normal: {
label: {
show: false
}
}
},
data: [
{
value: 0,
itemStyle: {
normal: {
color: 'rgba(255, 255, 255, 1)'
}
}
}
]
}
]
};
// Set options and render right chart
rightChart.setOption(rightOption);
window.addEventListener("resize", handleResize);
window.addEventListener('resize', handleResize);
});
onBeforeUnmount(() => {
leftChart?.dispose();
rightChart?.dispose();
window.removeEventListener("resize", handleResize);
window.removeEventListener('resize', handleResize);
});
</script>

5262
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save