Dashboard.vue 5.2 KB

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