Dashboard.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="chart" :id="id"></div>
  3. </template>
  4. <script>
  5. import util from "@/helper/util.js";
  6. import partten from "@/helper/partten.js";
  7. import * as echarts from "echarts";
  8. export default {
  9. name: "Dashboard-chart",
  10. componentName: "Dashboard-chart",
  11. props: {
  12. width: {
  13. type: String,
  14. default: "100%",
  15. },
  16. height: {
  17. type: String,
  18. default: "100%",
  19. },
  20. value: {
  21. type: Number,
  22. default: 50,
  23. },
  24. max: {
  25. type: Number,
  26. default: 100,
  27. },
  28. },
  29. data() {
  30. return {
  31. id: "",
  32. chart: null,
  33. };
  34. },
  35. computed: {},
  36. methods: {
  37. initChart() {
  38. let chart = echarts.init(this.$el);
  39. let option = {
  40. tooltip: {
  41. formatter: "{a} <br/>{b} : {c}%",
  42. },
  43. series: [
  44. {
  45. name: "内部进度条",
  46. type: "gauge",
  47. // center: ['50%', '50%'],
  48. radius: "80%",
  49. z: 4,
  50. splitNumber: 10,
  51. axisLine: {
  52. lineStyle: {
  53. color: [
  54. [this.value / 100, partten.getColor("green")],
  55. [1, partten.getColor("gray")],
  56. ],
  57. width: 8,
  58. },
  59. },
  60. axisLabel: {
  61. show: false,
  62. },
  63. axisTick: {
  64. show: false,
  65. },
  66. splitLine: {
  67. show: false,
  68. },
  69. itemStyle: {
  70. show: false,
  71. },
  72. detail: {
  73. formatter: function(value) {
  74. if (value !== 0) {
  75. var num = Math.round(value);
  76. return parseInt(num).toFixed(0) + "";
  77. } else {
  78. return 0;
  79. }
  80. },
  81. offsetCenter: [0, "75%"],
  82. textStyle: {
  83. padding: [0, 0, 0, 0],
  84. fontSize: 20,
  85. fontWeight: "700",
  86. color: partten.getColor("green"),
  87. },
  88. },
  89. title: {
  90. show: false,
  91. },
  92. data: [
  93. {
  94. name: this.value,
  95. value: this.value,
  96. },
  97. ],
  98. pointer: {
  99. show: true,
  100. length: "70%",
  101. radius: "20%",
  102. width: 2, //指针粗细
  103. itemStyle: {
  104. color: partten.getColor("green"),
  105. },
  106. },
  107. animationDuration: 1500,
  108. },
  109. // 内圆
  110. {
  111. name: "内圆",
  112. type: "pie",
  113. hoverAnimation: false,
  114. legendHoverLink: false,
  115. radius: "8%",
  116. z: 4,
  117. labelLine: {
  118. normal: {
  119. show: false,
  120. },
  121. },
  122. data: [
  123. {
  124. value: 0,
  125. },
  126. {
  127. value: 10,
  128. itemStyle: {
  129. normal: {
  130. color: "#161f1e",
  131. },
  132. emphasis: {
  133. color: "#161f1e",
  134. },
  135. },
  136. },
  137. ],
  138. },
  139. // 圆环
  140. {
  141. name: "小圆形",
  142. type: "pie",
  143. hoverAnimation: false,
  144. legendHoverLink: false,
  145. radius: ["8%", "5%"],
  146. z: 5,
  147. labelLine: {
  148. normal: {
  149. show: false,
  150. },
  151. },
  152. data: [
  153. {
  154. value: 0,
  155. },
  156. {
  157. value: 10,
  158. itemStyle: {
  159. normal: {
  160. color: partten.getColor("green"),
  161. },
  162. },
  163. },
  164. ],
  165. },
  166. {
  167. name: "外部刻度",
  168. type: "gauge",
  169. radius: "94%",
  170. min: 0, //最小刻度
  171. max: this.max, //最大刻度
  172. splitNumber: 4, //刻度数量
  173. startAngle: 225,
  174. endAngle: -45,
  175. axisLine: {
  176. show: false,
  177. },
  178. //仪表盘轴线
  179. axisLabel: {
  180. show: true,
  181. distance: 16,
  182. fontSize: 12,
  183. },
  184. //刻度标签。
  185. axisTick: {
  186. show: true,
  187. splitNumber: 4,
  188. lineStyle: {
  189. color: partten.getColor("gray"), //用颜色渐变函数不起作用
  190. width: 1,
  191. },
  192. length: 4,
  193. },
  194. //刻度样式
  195. splitLine: {
  196. show: false,
  197. },
  198. //分隔线样式
  199. detail: {
  200. show: false,
  201. },
  202. pointer: {
  203. show: true,
  204. },
  205. },
  206. ],
  207. };
  208. chart.setOption(option);
  209. },
  210. },
  211. created() {
  212. this.id = "pie-chart-" + util.newGUID();
  213. },
  214. mounted() {
  215. this.$nextTick(() => {
  216. this.$el.style.width = this.width;
  217. this.$el.style.height = this.height;
  218. this.initChart();
  219. });
  220. },
  221. updated() {
  222. this.$nextTick(() => {
  223. this.initChart();
  224. });
  225. },
  226. };
  227. </script>
  228. <style lang="less">
  229. .chart {
  230. width: 100%;
  231. height: 100%;
  232. display: inline-block;
  233. }
  234. </style>