percent-bar-3.vue 4.3 KB

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