radar-pie-chart.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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: "radar-pie",
  10. componentName: "radar-pie",
  11. props: {
  12. width: {
  13. type: String,
  14. default: "100%",
  15. },
  16. height: {
  17. type: String,
  18. default: "18.519vh",
  19. },
  20. // 百分比值
  21. // 外部饼图数据
  22. list: {
  23. type: Array,
  24. default: () => [
  25. {
  26. value: 310,
  27. name: "邮件营销",
  28. },
  29. {
  30. value: 234,
  31. name: "联盟广告",
  32. },
  33. {
  34. value: 335,
  35. name: "视频广告",
  36. },
  37. {
  38. value: 548,
  39. name: "百度",
  40. },
  41. {
  42. value: 351,
  43. name: "谷歌",
  44. },
  45. ],
  46. },
  47. title: {
  48. type: String,
  49. default: "title",
  50. },
  51. },
  52. data() {
  53. return {
  54. id: "",
  55. chart: null,
  56. };
  57. },
  58. computed: {},
  59. methods: {
  60. initChart() {
  61. let option = {
  62. color: [
  63. "#05bb4c",
  64. "#4b55ae",
  65. "#fa8c16",
  66. "#f8de5b",
  67. "#1a93cf",
  68. "#c531c7",
  69. "#bd3338",
  70. ],
  71. tooltip: {
  72. trigger: "item",
  73. backgroundColor: "rgba(0,0,0,0.4)",
  74. borderColor: partten.getColor("gray"),
  75. textStyle: {
  76. color: "#fff",
  77. fontSize: util.vh(16),
  78. },
  79. },
  80. grid: {
  81. top: 8,
  82. left: 8,
  83. right: 8,
  84. bottom: 8,
  85. containLabel: true,
  86. },
  87. legend: {
  88. icon: "circle",
  89. orient: "vertical",
  90. top: "center",
  91. right: "0",
  92. align: "left",
  93. textStyle: {
  94. color: "#fff",
  95. },
  96. itemGap: 8,
  97. },
  98. radar: {
  99. center: ["35%", "50%"],
  100. radius: "80%",
  101. startAngle: 90,
  102. splitNumber: 8,
  103. shape: "circle",
  104. splitArea: {
  105. areaStyle: {
  106. color: ["transparent"],
  107. },
  108. },
  109. axisLabel: {
  110. show: false,
  111. fontSize: 18,
  112. color: "#fff",
  113. fontStyle: "normal",
  114. fontWeight: "normal",
  115. },
  116. axisLine: {
  117. show: true,
  118. lineStyle: {
  119. color: "#606769", //
  120. },
  121. },
  122. splitLine: {
  123. show: true,
  124. lineStyle: {
  125. color: "#606769", //
  126. },
  127. },
  128. indicator: [
  129. {
  130. name: "",
  131. max: 100,
  132. },
  133. {
  134. name: "",
  135. max: 100,
  136. },
  137. {
  138. name: "",
  139. max: 100,
  140. },
  141. {
  142. name: "",
  143. max: 100,
  144. },
  145. {
  146. name: "",
  147. max: 100,
  148. },
  149. {
  150. name: "",
  151. max: 100,
  152. },
  153. {
  154. name: "",
  155. max: 100,
  156. },
  157. {
  158. name: "",
  159. max: 100,
  160. },
  161. {
  162. name: "",
  163. max: 100,
  164. },
  165. {
  166. name: "",
  167. max: 100,
  168. },
  169. {
  170. name: "",
  171. max: 100,
  172. },
  173. {
  174. name: "",
  175. max: 100,
  176. },
  177. {
  178. name: "",
  179. max: 100,
  180. },
  181. {
  182. name: "",
  183. max: 100,
  184. },
  185. {
  186. name: "",
  187. max: 100,
  188. },
  189. {
  190. name: "",
  191. max: 100,
  192. },
  193. {
  194. name: "",
  195. max: 100,
  196. },
  197. {
  198. name: "",
  199. max: 100,
  200. },
  201. {
  202. name: "",
  203. max: 100,
  204. },
  205. {
  206. name: "",
  207. max: 100,
  208. },
  209. {
  210. name: "",
  211. max: 100,
  212. },
  213. {
  214. name: "",
  215. max: 100,
  216. },
  217. {
  218. name: "",
  219. max: 100,
  220. },
  221. {
  222. name: "",
  223. max: 100,
  224. },
  225. ],
  226. },
  227. series: [
  228. {
  229. name: this.title,
  230. type: "pie",
  231. clockwise: false,
  232. startAngle: 90,
  233. radius: "70%",
  234. center: ["35%", "50%"],
  235. hoverAnimation: false,
  236. roseType: "radius", //area
  237. data: this.list,
  238. label: {
  239. show: false,
  240. },
  241. labelLine: {
  242. normal: {
  243. length: 20,
  244. length2: 30,
  245. lineStyle: {
  246. width: 1,
  247. },
  248. },
  249. },
  250. },
  251. ],
  252. };
  253. this.chart.setOption(option);
  254. },
  255. },
  256. created() {
  257. this.id = "pie-chart-" + util.newGUID();
  258. },
  259. mounted() {
  260. this.$el.style.width = this.width;
  261. this.$el.style.height = this.height;
  262. this.chart = echarts.init(this.$el);
  263. this.initChart();
  264. },
  265. updated() {
  266. this.initChart();
  267. },
  268. };
  269. </script>
  270. <style lang="less">
  271. .chart {
  272. width: 100%;
  273. height: 100%;
  274. display: inline-block;
  275. }
  276. </style>