想要实现以上效果,代码如下
<template>
<div>
<div class="fourth-chart">
<div id="fourthChart" style="width: 100%; height: 100%"></div>
</div>
</div>
</template>
<script>
import echarts from "echarts";
import echarts5 from "echarts5";
export default {
mounted() {
this.initFourthChart();
},
methods: {
//四种仪表盘
initFourthChart() {
let fourthChart = this.$echarts5.init(
document.getElementById("fourthChart")
); //获取容器元素
let option = {
backgroundColor: "#041947",
tooltip: {
backgroundColor: "rgba(3, 25, 79,1)",
borderWidth: 1,
borderColor: "#32A1FF",
padding: 5,
textStyle: {
color: "#fff",
},
// ...其他配置
extraCssText: "width: auto !important; height: auto !important;", // 或者具体的宽度高度
formatter: function (params) {
return `${params.name}: ${params.value}% (${params.data.count}件)`;
},
},
series: [
{
data: [
{
value: 55,
count: 10,
name: "第一种",
},
],
title: {
offsetCenter: ["5%", "75%"],
fontSize: 16,
color: "#fff",
show: true,
},
name: "最外层",
type: "gauge",
roundCap: true,
radius: "80%",
center: ["12%", "60%"],
splitNumber: 0, //刻度数量
startAngle: 180,
endAngle: 0,
z: 4,
zlevel: 0,
axisLine: {
show: true,
roundCap: true,
lineStyle: {
// 轴线样式
width: 8, // 宽度
color: [
[
1,
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "#14307b", // 渐变起始颜色
},
{
offset: 1,
color: "#14307b", // 渐变结束颜色
},
],
},
],
],
},
},
progress: {
// 进度条填充
show: true,
roundCap: true,
width: 15,
},
//分隔线样式
splitLine: {
show: false,
},
axisLabel: {
show: false,
},
axisTick: {
show: true,
},
anchor: {
show: true,
size: 5,
showAbove: true,
itemStyle: {
color: "#1dd7eb",
},
},
pointer: {
icon: "path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z",
show: true,
length: "90%",
width: 10,
offsetCenter: [0, "5%"],
itemStyle: {
color: "#178ffe",
},
},
detail: {
color: "#385BF7",
fontStyle: "normal",
fontWeight: "bold",
fontFamily: "D-DIN",
fontSize: 16,
offsetCenter: [0, "40%"],
formatter: "{value}%",
},
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
{
offset: 0,
color: "#2EE5E3",
},
{
offset: 1,
color: "#385BF7",
},
]),
barGap: "-100%",
},
{
name: "里边刻度",
type: "gauge",
radius: "80%",
center: ["12%", "60%"],
// distance : 100,
startAngle: 180,
endAngle: 0,
axisLine: {
show: false,
}, //仪表盘轴线
axisLabel: {
show: false,
color: "#FFFFFF",
distance: 16,
}, //刻度标签。
axisTick: {
show: true,
splitNumber: 1,
lineStyle: {
color: "#4381ea",
width: 1,
},
distance: 10,
length: 10,
},
splitLine: {
show: false,
},
detail: {
show: false,
},
pointer: {
show: false,
},
},
{
data: [
{
value: 70,
count: 10,
name: "第二种",
},
],
title: {
offsetCenter: ["5%", "75%"],
fontSize: 16,
color: "#fff",
show: true,
},
name: "最外层",
type: "gauge",
roundCap: true,
radius: "80%",
center: ["38%", "60%"],
splitNumber: 0, //刻度数量
startAngle: 180,
endAngle: 0,
z: 4,
zlevel: 0,
axisLine: {
show: true,
roundCap: true,
lineStyle: {
// 轴线样式
width: 8, // 宽度
color: [
[
1,
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "#14307b", // 渐变起始颜色
},
{
offset: 1,
color: "#14307b", // 渐变结束颜色
},
],
},
],
],
},
},
progress: {
// 进度条填充
show: true,
roundCap: true,
width: 15,
},
//分隔线样式
splitLine: {
show: false,
},
axisLabel: {
show: false,
},
axisTick: {
show: true,
},
anchor: {
show: true,
size: 5,
showAbove: true,
itemStyle: {
color: "#3164fc",
},
},
pointer: {
icon: "path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z",
show: true,
length: "90%",
width: 10,
offsetCenter: [0, "5%"],
itemStyle: {
color: "#ae6aff",
},
},
detail: {
// backgroundColor: "#fff",
color: "#9666ff",
fontStyle: "normal",
fontFamily: "D-DIN",
fontSize: 16,
offsetCenter: [0, "40%"],
formatter: "{value}%",
},
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
{
offset: 0,
color: "#3364fd",
},
{
offset: 1,
color: "#9666ff",
},
]),
barGap: "-100%",
},
{
name: "里边刻度",
type: "gauge",
radius: "80%",
center: ["38%", "60%"],
// distance : 100,
startAngle: 180,
endAngle: 0,
axisLine: {
show: false,
}, //仪表盘轴线
axisLabel: {
show: false,
color: "#FFFFFF",
distance: 16,
}, //刻度标签。
axisTick: {
show: true,
splitNumber: 1,
lineStyle: {
color: "#4381ea",
width: 1,
},
distance: 10,
length: 10,
},
splitLine: {
show: false,
},
detail: {
show: false,
},
pointer: {
show: false,
},
},
{
data: [
{
value: 60,
count: 10,
name: "第三种",
},
],
title: {
offsetCenter: ["5%", "75%"],
fontSize: 16,
color: "#fff",
show: true,
},
name: "最外层",
type: "gauge",
roundCap: true,
radius: "80%",
center: ["63%", "60%"],
splitNumber: 0, //刻度数量
startAngle: 180,
endAngle: 0,
z: 4,
zlevel: 0,
axisLine: {
show: true,
roundCap: true,
lineStyle: {
// 轴线样式
width: 8, // 宽度
color: [
[
1,
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "#14307b", // 渐变起始颜色
},
{
offset: 1,
color: "#14307b", // 渐变结束颜色
},
],
},
],
],
},
},
progress: {
// 进度条填充
show: true,
roundCap: true,
width: 15,
},
//分隔线样式
splitLine: {
show: false,
},
axisLabel: {
show: false,
},
axisTick: {
show: true,
},
anchor: {
show: true,
size: 5,
showAbove: true,
itemStyle: {
color: "#fdc06a",
},
},
pointer: {
icon: "path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z",
show: true,
length: "90%",
width: 10,
offsetCenter: [0, "5%"],
itemStyle: {
color: "#ff6f27",
},
},
detail: {
// backgroundColor: "#fff",
color: "#ff6922",
fontStyle: "normal",
fontFamily: "D-DIN",
fontSize: 16,
offsetCenter: [0, "40%"],
formatter: "{value}%",
},
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
{
offset: 0,
color: "#ffc069",
},
{
offset: 1,
color: "#ff6922",
},
]),
barGap: "-100%",
},
{
name: "里边刻度",
type: "gauge",
radius: "80%",
center: ["63%", "60%"],
// distance : 100,
startAngle: 180,
endAngle: 0,
axisLine: {
show: false,
}, //仪表盘轴线
axisLabel: {
show: false,
color: "#14307b",
distance: 16,
}, //刻度标签。
axisTick: {
show: true,
splitNumber: 1,
lineStyle: {
color: "#4381ea",
width: 1,
},
distance: 10,
length: 10,
},
splitLine: {
show: false,
},
detail: {
show: false,
},
pointer: {
show: false,
},
},
{
data: [
{
value: 85,
count: 10,
name: "第四种",
},
],
title: {
offsetCenter: ["5%", "75%"],
fontSize: 16,
color: "#fff",
show: true,
},
name: "最外层",
type: "gauge",
roundCap: true,
radius: "80%",
center: ["88%", "60%"],
splitNumber: 0, //刻度数量
startAngle: 180,
endAngle: 0,
z: 4,
zlevel: 0,
axisLine: {
show: true,
roundCap: true,
lineStyle: {
// 轴线样式
width: 8, // 宽度
color: [
[
1,
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "#14307b", // 渐变起始颜色
},
{
offset: 1,
color: "#14307b", // 渐变结束颜色
},
],
},
],
],
},
},
progress: {
// 进度条填充
show: true,
roundCap: true,
width: 15,
},
//分隔线样式
splitLine: {
show: false,
},
axisLabel: {
show: false,
},
axisTick: {
show: true,
},
anchor: {
show: true,
size: 5,
showAbove: true,
itemStyle: {
color: "#fd5b20",
},
},
pointer: {
icon: "path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z",
show: true,
length: "90%",
width: 10,
offsetCenter: [0, "5%"],
itemStyle: {
color: "#f13b39",
},
},
detail: {
// backgroundColor: "#fff",
color: "#f13b39",
fontStyle: "normal",
fontFamily: "D-DIN",
fontSize: 16,
offsetCenter: [0, "40%"],
formatter: "{value}%",
},
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
{
offset: 0,
color: "#ff6d27",
},
{
offset: 1,
color: "#f13b39",
},
]),
barGap: "-100%",
},
{
name: "里边刻度",
type: "gauge",
radius: "80%",
center: ["88%", "60%"],
// distance : 100,
startAngle: 180,
endAngle: 0,
axisLine: {
show: false,
}, //仪表盘轴线
axisLabel: {
show: false,
color: "#FFFFFF",
distance: 16,
}, //刻度标签。
axisTick: {
show: true,
splitNumber: 1,
lineStyle: {
color: "#4381ea",
width: 1,
},
distance: 10,
length: 10,
},
splitLine: {
show: false,
},
detail: {
show: false,
},
pointer: {
show: false,
},
},
],
};
//防止越界,重绘canvas
window.onresize = fourthChart.resize;
fourthChart.setOption(option); //设置option
},
},
};
</script>
<style lang="scss" scoped>
.fourth-chart {
width: 100%;
height: 46%;
#fourthChart {
width: 100%;
height: 100%;
div {
width: 100% !important;
height: 100% !important;
canvas {
width: 100% !important;
height: 100% !important;
}
}
}
}
</style>