ex1.vue
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<div class="echart" id="mychart2" :style="myChartStyle"></div>
</template>
<script>
import * as echarts from "echarts";
export default {
props: {
percentage: {
type: String,
default: "",
},
},
data() {
return {
myChartStyle: { float: "left", width: "100%", height: "300px" }, //图表样式
};
},
mounted() {
this.initEcharts();
},
methods: {
initEcharts() {
console.log(Number(this.percentage))
const option = {
// tooltip: {
// formatter: "{a} <br/>{b} : {c}%",
// },
series: [
{
type: "gauge",
min: 0,
max: 1000,
splitNumber: 10,
radius: "85%",
axisLine: {
lineStyle: {
width: 15,
color: [
[0.3, "#67e0e3"],
[0.7, "#37a2da"],
[1, "#fd666d"],
],
},
},
pointer: {
itemStyle: {
color: "auto",
},
},
axisTick: {
distance: -15,
length: 6,
lineStyle: {
color: "#fff",
width: 2,
},
},
splitLine: {
distance: -30,
length: 20,
lineStyle: {
color: "#fff",
width: 4,
},
},
axisLabel: {
color: "auto",
distance: 0,
fontSize: 10,
},
detail: {
valueAnimation: true,
formatter: "{value}",
color: "auto",
},
data: [
{
value: Number(this.percentage),
},
],
},
],
};
const myChart = echarts.init(document.getElementById("mychart2"));
myChart.clear()
myChart.setOption(option, true)
//随着屏幕大小调节图表
window.addEventListener("resize", () => {
myChart.resize();
});
},
},
};
</script>