radar-pie-chart.vue 9.4 KB

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