percent-bar.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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: "dsah-pie",
  10. componentName: "dsah-pie",
  11. props: {
  12. width: {
  13. type: String,
  14. default: "7.407vh",
  15. },
  16. height: {
  17. type: String,
  18. default: "7.407vh",
  19. },
  20. // 传入数据
  21. value: {
  22. type: Number,
  23. default: 25,
  24. },
  25. // 颜色 green yellow (partten中支持的颜色)
  26. color: {
  27. type: String,
  28. default: "green",
  29. },
  30. },
  31. data() {
  32. return {
  33. id: "",
  34. chart: null,
  35. };
  36. },
  37. computed: {
  38. colorValue() {
  39. return partten.getColor(this.color);
  40. },
  41. text() {
  42. return this.value + "%";
  43. },
  44. },
  45. created() {
  46. this.id = "pie-chart-" + util.newGUID();
  47. },
  48. methods: {
  49. initChart() {
  50. let chart = echarts.init(this.$el);
  51. let option = {
  52. title: [
  53. {
  54. text: this.text,
  55. x: "45%",
  56. y: "32%",
  57. textAlign: "center",
  58. textStyle: {
  59. fontSize: 14,
  60. fontFamily: "Bicubik",
  61. fontWeight: "600",
  62. color: partten.getColor(this.colors),
  63. textAlign: "center",
  64. },
  65. },
  66. ],
  67. polar: {
  68. radius: ["100%", "85%"],
  69. center: ["50%", "50%"],
  70. },
  71. angleAxis: {
  72. max: 100,
  73. show: false,
  74. startAngle: 180,
  75. },
  76. radiusAxis: {
  77. type: "category",
  78. show: true,
  79. axisLabel: {
  80. show: false,
  81. },
  82. axisLine: {
  83. show: false,
  84. },
  85. axisTick: {
  86. show: false,
  87. },
  88. },
  89. series: [
  90. {
  91. name: "",
  92. z: "3",
  93. type: "bar",
  94. roundCap: true,
  95. barWidth: 60,
  96. showBackground: true,
  97. backgroundStyle: {
  98. color: partten.getColor(this.colors) + "30",
  99. },
  100. data: [this.value],
  101. coordinateSystem: "polar",
  102. itemStyle: {
  103. normal: {
  104. color: partten.getColor(this.colors),
  105. // new echarts.graphic.LinearGradient(1, 0, 0, 0, [
  106. // {
  107. // offset: 0,
  108. // color: "#0ff",
  109. // },
  110. // {
  111. // offset: 1,
  112. // color: "#02aeff",
  113. // },
  114. // ]),
  115. },
  116. },
  117. },
  118. {
  119. type: "pie",
  120. radius: ["100%", "97%"],
  121. startAngle: 180,
  122. center: ["50%", "50%"],
  123. data: [
  124. {
  125. hoverOffset: 1,
  126. value: 100,
  127. name: "",
  128. itemStyle: {
  129. color: partten.getColor(this.colors),
  130. },
  131. label: {
  132. show: false,
  133. },
  134. labelLine: {
  135. normal: {
  136. smooth: true,
  137. lineStyle: {
  138. width: 0,
  139. },
  140. },
  141. },
  142. hoverAnimation: false,
  143. },
  144. {
  145. label: {
  146. show: false,
  147. },
  148. labelLine: {
  149. normal: {
  150. smooth: true,
  151. lineStyle: {
  152. width: 0,
  153. },
  154. },
  155. },
  156. value: 0,
  157. hoverAnimation: false,
  158. itemStyle: {
  159. color: "transparent",
  160. },
  161. },
  162. ],
  163. },
  164. ],
  165. };
  166. chart.setOption(option);
  167. },
  168. },
  169. mounted() {
  170. this.$nextTick(() => {
  171. this.$el.style.width = this.width;
  172. this.$el.style.height = this.height;
  173. this.initChart();
  174. });
  175. },
  176. updated() {
  177. this.$nextTick(() => {
  178. this.initChart();
  179. });
  180. },
  181. };
  182. </script>
  183. <style lang="less" scoped>
  184. .chart {
  185. width: 100%;
  186. height: 100%;
  187. display: block;
  188. margin: auto;
  189. }
  190. </style>