index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div ref="echartD" style="width: 100%; height: 100%; display: flex; justify-content: center"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. export default {
  7. props: {
  8. dataMap: { type: Number, default: () => 0 },
  9. },
  10. data() {
  11. return {};
  12. },
  13. watch: {
  14. dataMap(val) {
  15. this.getData(val);
  16. },
  17. },
  18. mounted() {
  19. this.getData();
  20. },
  21. methods: {
  22. getData() {
  23. let echartsMap = this.$echarts.getInstanceByDom(this.$refs.echartD);
  24. if (echartsMap == null) {
  25. echartsMap = this.$echarts.init(this.$refs.echartD);
  26. }
  27. echartsMap.setOption({
  28. title: {
  29. show: true,
  30. text: "水源完好率",
  31. left: "center",
  32. right: "center",
  33. bottom: "center",
  34. top: "52%",
  35. center: 20,
  36. textStyle: {
  37. color: "#FFF",
  38. fontSize: "0.225rem",
  39. align: "center",
  40. fontFamily: "syhtN",
  41. },
  42. },
  43. series: [
  44. {
  45. name: "刻度",
  46. type: "gauge",
  47. radius: "80%",
  48. min: 0, //最小刻度
  49. max: 100, //最大刻度
  50. startAngle: 225, //开始角度 左侧角度
  51. endAngle: -135, //结束角度 右侧
  52. z: 4,
  53. splitNumber: 10,
  54. axisLine: {
  55. show: true,
  56. lineStyle: {
  57. width: 1,
  58. color: [[1, "rgba(0,0,0,0)"]],
  59. },
  60. }, //仪表盘轴线
  61. axisLabel: {
  62. show: false,
  63. color: "#00faff",
  64. fontSize: 14,
  65. distance: 20,
  66. formatter: function (v) {
  67. return v;
  68. },
  69. }, //刻度标签。
  70. axisTick: {
  71. show: true,
  72. splitNumber: 6,
  73. lineStyle: {
  74. color: "#00faff",
  75. width: 1,
  76. // length:10
  77. },
  78. length: 5,
  79. }, //刻度样式
  80. splitLine: {
  81. show: true,
  82. length: -10,
  83. lineStyle: {
  84. color: "#00faff",
  85. width: 1,
  86. },
  87. }, //分隔线样式
  88. },
  89. {
  90. type: "gauge",
  91. radius: "60%",
  92. // center: ["50%","70%"],
  93. splitNumber: 5, //刻度数量
  94. startAngle: 225, //开始角度 左侧角度
  95. endAngle: -135, //结束角度 右侧
  96. z: 4,
  97. axisLine: {
  98. show: true,
  99. roundCap: true,
  100. lineStyle: {
  101. width: 10,
  102. color: [
  103. [
  104. this.dataMap > 1 ? 1 : this.dataMap,
  105. new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  106. { offset: 0, color: "#0099ff" },
  107. { offset: 1, color: "#00d5ff" },
  108. ]),
  109. ],
  110. // [1, "#111F42"],
  111. ],
  112. },
  113. },
  114. //分隔线样式。
  115. splitLine: {
  116. show: false,
  117. },
  118. axisLabel: {
  119. show: false,
  120. },
  121. axisTick: {
  122. show: false,
  123. },
  124. pointer: {
  125. show: false,
  126. length: "70%",
  127. width: "2%",
  128. },
  129. title: {
  130. show: false,
  131. offsetCenter: [0, 0], // x, y,单位px
  132. // textStyle: {
  133. // fontWeight: "100",
  134. // color: "#0ab7ff",
  135. // fontSize: 30,
  136. // },
  137. },
  138. //仪表盘详情,用于显示数据。
  139. detail: {
  140. show: true,
  141. offsetCenter: [0, "-20%"],
  142. color: "#ffffff",
  143. fontSize: "0.625rem",
  144. color: "#FFF",
  145. fontWeight: "500",
  146. fontFamily: "syhtN",
  147. formatter: function (v) {
  148. return v * 100 + "%";
  149. },
  150. },
  151. data: [
  152. {
  153. value: this.dataMap,
  154. },
  155. ],
  156. },
  157. {
  158. //内圆
  159. type: "pie",
  160. radius: "46%",
  161. center: ["50%", "50%"],
  162. z: 3,
  163. itemStyle: {
  164. color: new echarts.graphic.RadialGradient(
  165. 0.5,
  166. 0.5,
  167. 0.8,
  168. [
  169. {
  170. offset: 0,
  171. color: "#00b8f8",
  172. },
  173. {
  174. offset: 0.5,
  175. color: "#0068d4",
  176. },
  177. {
  178. offset: 1,
  179. color: "#0068d3",
  180. },
  181. ],
  182. false
  183. ),
  184. label: {
  185. show: false,
  186. },
  187. labelLine: {
  188. show: false,
  189. },
  190. },
  191. emphasis:{scale: 0.1},
  192. label: {
  193. show: false,
  194. },
  195. tooltip: {
  196. show: false,
  197. },
  198. data: [100],
  199. },
  200. // 刻度圈
  201. {
  202. type: "pie",
  203. radius: ["0%", "90%"],
  204. center: ["50%", "50%"],
  205. avoidLabelOverlap: false,
  206. z: 3,
  207. label: {
  208. show: false,
  209. position: "center",
  210. },
  211. itemStyle: {
  212. color: {
  213. type: "linear",
  214. x: 0,
  215. y: 0,
  216. x2: 0,
  217. y2: 1,
  218. colorStops: [
  219. {
  220. offset: 0,
  221. color: "#122c7a",
  222. },
  223. {
  224. offset: 1,
  225. color: "#122c7a",
  226. },
  227. ],
  228. },
  229. },
  230. labelLine: {
  231. show: false,
  232. },
  233. data: [
  234. {
  235. value: 100,
  236. },
  237. ],
  238. },
  239. //最外层圈
  240. {
  241. type: "pie",
  242. radius: ["0%", "100%"],
  243. center: ["50%", "50%"],
  244. avoidLabelOverlap: false,
  245. z: 2,
  246. emphasis:{scale: 0.1},
  247. label: {
  248. show: false,
  249. position: "center",
  250. },
  251. itemStyle: {
  252. color: {
  253. type: "linear",
  254. x: 0,
  255. y: 0,
  256. x2: 0,
  257. y2: 1,
  258. colorStops: [
  259. {
  260. offset: 0,
  261. color: "#0b1f61",
  262. },
  263. {
  264. offset: 1,
  265. color: "#0b1f61",
  266. },
  267. ],
  268. },
  269. },
  270. labelLine: {
  271. show: false,
  272. },
  273. data: [
  274. {
  275. value: 100,
  276. },
  277. ],
  278. },
  279. ],
  280. });
  281. window.onresize = function () {
  282. echartsMap.resize();
  283. };
  284. },
  285. },
  286. };
  287. </script>
  288. <style scoped></style>