pieCamera.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div
  3. ref="main"
  4. :class="className"
  5. :style="{ height: height, width: width }"
  6. ></div>
  7. </template>
  8. <script>
  9. import echarts from "echarts";
  10. import resize from "./mixins/resize";
  11. export default {
  12. mixins: [resize],
  13. props: {
  14. className: {
  15. type: String,
  16. default: "chart",
  17. },
  18. width: {
  19. type: String,
  20. default: "100%",
  21. },
  22. height: {
  23. type: String,
  24. default: "100%",
  25. },
  26. perData: {
  27. type: Array,
  28. default: () => [ {
  29. name: "摄像头",
  30. value: [39],
  31. // nAmount: 566557.14,
  32. }],
  33. },
  34. },
  35. data() {
  36. return {
  37. chart: null,
  38. };
  39. },
  40. mounted() {
  41. this.$nextTick(() => {
  42. this.initChart();
  43. });
  44. },
  45. beforeDestroy() {
  46. if (!this.chart) {
  47. return;
  48. }
  49. this.chart.dispose();
  50. this.chart = null;
  51. },
  52. methods: {
  53. initChart() {
  54. // 基于准备好的dom,初始化echarts实例
  55. this.chart = echarts.init(this.$refs.main);
  56. var color = ["#C8E4FF", "#0483FF", "#0483FF"];
  57. var title = this.perData[0].value;
  58. var per = "%";
  59. // 指定图表的配置项和数据
  60. this.chart.setOption({
  61. title: {
  62. text: "{a|" + title + "}{b|" + per + "}",
  63. textStyle: {
  64. rich: {
  65. a: {
  66. fontSize: 25,
  67. color: color[2],
  68. fontFamily: "impact",
  69. },
  70. b: {
  71. fontSize: 16,
  72. fontFamily: "impact",
  73. color: color[2],
  74. },
  75. },
  76. },
  77. subtext: "异常率",
  78. subtextStyle: {
  79. color: "#fff",
  80. fontSize: "12",
  81. },
  82. itemGap: 3,
  83. left: "center",
  84. top: "37%", //aa圈内标题的位置
  85. },
  86. graphic: [
  87. {
  88. type: "text",
  89. z: 100,
  90. left: "center",
  91. top: "90%", // aa 底下标题w在容器里的位置
  92. style: {
  93. fill: "#fff",
  94. text: this.perData[0].name,
  95. font: "1.6rem Microsoft YaHei", // aa 底下标题字体大小
  96. },
  97. },
  98. ],
  99. tooltip: {
  100. //aa 手指移入
  101. formatter: function (params) {
  102. return (
  103. '<span style="color: #fff;">占比:' + params.value + "%</span>"
  104. );
  105. },
  106. },
  107. angleAxis: {
  108. max: 100,
  109. clockwise: false, // 逆时针
  110. // 隐藏刻度线
  111. show: false,
  112. startAngle: 90,
  113. },
  114. radiusAxis: {
  115. type: "category",
  116. show: true,
  117. axisLabel: {
  118. show: false,
  119. },
  120. axisLine: {
  121. show: false,
  122. },
  123. axisTick: {
  124. show: false,
  125. },
  126. },
  127. polar: [
  128. {
  129. center: ["50%", "50%"], //中心点位置 aa填充圈的中心位置
  130. radius: "100%", //图形大小 aa填充圈的图形大小
  131. },
  132. ],
  133. series: [
  134. {
  135. name: "小环",
  136. type: "gauge",
  137. splitNumber: 15,
  138. radius: "75%", //aa发散圈的大小
  139. center: ["50%", "50%"],
  140. startAngle: 0,
  141. endAngle: 359.9999,
  142. axisLine: {
  143. show: false,
  144. },
  145. axisTick: {
  146. show: true,
  147. lineStyle: {
  148. color: color[1],
  149. width: 1, // aa发散圈的粗细
  150. shadowBlur: 1,
  151. shadowColor: color[1],
  152. },
  153. length: 8, // aa发散圈的长度
  154. splitNumber: 5, //aa发散圈每一条间隔
  155. },
  156. splitLine: {
  157. show: false,
  158. },
  159. axisLabel: {
  160. show: false,
  161. },
  162. detail: {
  163. show: false,
  164. },
  165. },
  166. {
  167. type: "bar",
  168. z: 10,
  169. data: this.perData[0].value,
  170. showBackground: false,
  171. backgroundStyle: {
  172. color: color[1],
  173. borderWidth: 10,
  174. width: 10,
  175. },
  176. coordinateSystem: "polar",
  177. // roundCap: true, //aa填充圈圆角
  178. barWidth: 7, //aa填充圈宽度
  179. itemStyle: {
  180. normal: {
  181. opacity: 1,
  182. color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
  183. {
  184. offset: 0,
  185. color: color[0],
  186. },
  187. {
  188. offset: 1,
  189. color: color[1],
  190. },
  191. ]),
  192. shadowBlur: 5,
  193. shadowColor: "#2A95F9",
  194. },
  195. },
  196. },
  197. {
  198. type: "pie",
  199. name: "内层细圆环",
  200. radius: ["50%", "52%"], //aa内层细圆环
  201. center: ["50%", "50%"],
  202. startAngle: 120,
  203. hoverAnimation: false,
  204. clockWise: true,
  205. barWidth: 1,
  206. itemStyle: {
  207. normal: {
  208. color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [
  209. {
  210. offset: 0,
  211. color: color[0],
  212. },
  213. {
  214. offset: 1,
  215. color: color[1],
  216. },
  217. ]),
  218. },
  219. },
  220. tooltip: {
  221. show: false,
  222. },
  223. label: {
  224. show: false,
  225. },
  226. data: [100],
  227. },
  228. ],
  229. });
  230. },
  231. },
  232. };
  233. </script>