pieSounder.vue 5.6 KB

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