radar-pie-chart.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. unit: {
  51. type: String,
  52. default: "",
  53. },
  54. },
  55. data() {
  56. return {
  57. id: "",
  58. chart: null,
  59. };
  60. },
  61. computed: {},
  62. methods: {
  63. initChart() {
  64. let that = this
  65. let option = {
  66. color: [
  67. "#3e73e9",
  68. "#4fa6e8",
  69. "#70d0f4",
  70. "#ffc149",
  71. "#ff7a87",
  72. "#70d0f4",
  73. "#cff4d8",
  74. ],
  75. tooltip: {
  76. trigger: "item",
  77. backgroundColor: this.$store.state.themeName === "dark" ?
  78. "rgba(0,0,0,0.4)" :
  79. "rgba(255,255,255,0.4)",
  80. borderColor: this.$store.state.themeName === "dark" ?
  81. partten.getColor("gray") :
  82. "#000",
  83. textStyle: {
  84. color: this.$store.state.themeName === "dark" ? "#fff" : "#000",
  85. fontSize: util.vh(16),
  86. },
  87. formatter: function(param) {
  88. let marker = '<span style="display:inline-block;margin-right:0.370vh;border-radius:0.926vh;width:0.926vh;height:0.926vh;background-color:' + partten.getColor("green") + ';"></span>';
  89. return param.seriesName + "<br >" + marker + param.name + ":" + param.value + that.unit;
  90. },
  91. },
  92. grid: {
  93. top: 8,
  94. left: 8,
  95. right: 8,
  96. bottom: 8,
  97. containLabel: true,
  98. },
  99. legend: {
  100. icon: "circle",
  101. orient: "vertical",
  102. top: "center",
  103. right: "0",
  104. align: "left",
  105. textStyle: {
  106. color: this.$store.state.themeName === "dark" ? "#fff" : "#000",
  107. },
  108. itemGap: 8,
  109. },
  110. // radar: {
  111. // center: ["25%", "50%"],
  112. // radius: "80%",
  113. // startAngle: 90,
  114. // splitNumber: 8,
  115. // shape: "circle",
  116. // splitArea: {
  117. // areaStyle: {
  118. // color: ["transparent"],
  119. // },
  120. // },
  121. // axisLabel: {
  122. // show: false,
  123. // fontSize: 18,
  124. // color: this.$store.state.themeName === "dark" ? "#fff" : "#000",
  125. // fontStyle: "normal",
  126. // fontWeight: "normal",
  127. // },
  128. // axisLine: {
  129. // show: true,
  130. // lineStyle: {
  131. // color: "#606769", //
  132. // },
  133. // },
  134. // splitLine: {
  135. // show: true,
  136. // lineStyle: {
  137. // color: "#606769", //
  138. // },
  139. // },
  140. // indicator: [{
  141. // name: "",
  142. // max: 100,
  143. // },
  144. // {
  145. // name: "",
  146. // max: 100,
  147. // },
  148. // {
  149. // name: "",
  150. // max: 100,
  151. // },
  152. // {
  153. // name: "",
  154. // max: 100,
  155. // },
  156. // {
  157. // name: "",
  158. // max: 100,
  159. // },
  160. // {
  161. // name: "",
  162. // max: 100,
  163. // },
  164. // {
  165. // name: "",
  166. // max: 100,
  167. // },
  168. // {
  169. // name: "",
  170. // max: 100,
  171. // },
  172. // {
  173. // name: "",
  174. // max: 100,
  175. // },
  176. // {
  177. // name: "",
  178. // max: 100,
  179. // },
  180. // {
  181. // name: "",
  182. // max: 100,
  183. // },
  184. // {
  185. // name: "",
  186. // max: 100,
  187. // },
  188. // {
  189. // name: "",
  190. // max: 100,
  191. // },
  192. // {
  193. // name: "",
  194. // max: 100,
  195. // },
  196. // {
  197. // name: "",
  198. // max: 100,
  199. // },
  200. // {
  201. // name: "",
  202. // max: 100,
  203. // },
  204. // {
  205. // name: "",
  206. // max: 100,
  207. // },
  208. // {
  209. // name: "",
  210. // max: 100,
  211. // },
  212. // {
  213. // name: "",
  214. // max: 100,
  215. // },
  216. // {
  217. // name: "",
  218. // max: 100,
  219. // },
  220. // {
  221. // name: "",
  222. // max: 100,
  223. // },
  224. // {
  225. // name: "",
  226. // max: 100,
  227. // },
  228. // {
  229. // name: "",
  230. // max: 100,
  231. // },
  232. // {
  233. // name: "",
  234. // max: 100,
  235. // },
  236. // ],
  237. // },
  238. series: [{
  239. name: this.title,
  240. type: "pie",
  241. clockwise: false,
  242. startAngle: 90,
  243. radius: "70%",
  244. center: ["25%", "50%"],
  245. hoverAnimation: false,
  246. // roseType: "radius", //area
  247. data: this.list,
  248. label: {
  249. show: false,
  250. },
  251. labelLine: {
  252. normal: {
  253. length: 20,
  254. length2: 30,
  255. lineStyle: {
  256. width: 1,
  257. },
  258. },
  259. },
  260. }, ],
  261. };
  262. this.chart.setOption(option);
  263. },
  264. },
  265. created() {
  266. this.id = "pie-chart-" + util.newGUID();
  267. },
  268. mounted() {
  269. this.$el.style.width = this.width;
  270. this.$el.style.height = this.height;
  271. this.chart = echarts.init(this.$el);
  272. this.initChart();
  273. },
  274. updated() {
  275. this.initChart();
  276. },
  277. watch: {
  278. list() {
  279. this.initChart();
  280. },
  281. },
  282. };
  283. </script>
  284. <style lang="less">
  285. .chart {
  286. width: 100%;
  287. height: 100%;
  288. display: inline-block;
  289. }
  290. </style>