PieAnimation.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. option = {
  2. backgroundColor: '#142468',
  3. title:{
  4. //text: '实时旋转饼图'
  5. },
  6. series: [
  7. {
  8. type: 'pie',
  9. zlevel: 1,
  10. silent: true,
  11. /*
  12. radius
  13. 饼图的半径。可以为如下类型:
  14. number:直接指定外半径值。
  15. string:例如,'20%',表示外半径为可视区尺寸(容器高宽中较小一项)的 20% 长度。
  16. Array.<number|string>:数组的第一项是内半径,第二项是外半径。每一项遵从上述 number string 的描述。
  17. */
  18. radius: ['98%', '97%'],
  19. hoverAnimation: false,
  20. color: "rgba(88,142,197,0.5)",
  21. // animation:false, //charts3 no
  22. label: {
  23. normal: {
  24. show: false
  25. },
  26. },
  27. labelLine: {
  28. normal: {
  29. show: false
  30. }
  31. },
  32. data: [1]
  33. },
  34. {
  35. type: 'pie',
  36. zlevel: 2,
  37. silent: true,
  38. radius: ['90%', '91%'],
  39. startAngle: 50,
  40. hoverAnimation: false,
  41. // animation:false, //charts3 no
  42. label: {
  43. normal: {
  44. show: false
  45. },
  46. },
  47. labelLine: {
  48. normal: {
  49. show: false
  50. }
  51. },
  52. data: _pie2()
  53. },
  54. {
  55. type: 'pie',
  56. zlevel: 3,
  57. silent: true,
  58. radius: ['88%', '87%'],
  59. label: {
  60. normal: {
  61. show: false
  62. },
  63. },
  64. labelLine: {
  65. normal: {
  66. show: false
  67. }
  68. },
  69. data: _pie2()
  70. },
  71. {
  72. type: 'pie',
  73. zlevel: 4,
  74. silent: true,
  75. radius: ['84%', '83%'],
  76. label: {
  77. normal: {
  78. show: false
  79. },
  80. },
  81. labelLine: {
  82. normal: {
  83. show: false
  84. }
  85. },
  86. data: _pie3()
  87. },
  88. {
  89. type: 'pie',
  90. zlevel: 5,
  91. silent: true,
  92. radius: ['80%', '78%'],
  93. color: ["#fc8d89", "#46d3f3", "rgba(203,203,203,.2)"],
  94. startAngle: 50,
  95. hoverAnimation: false,
  96. // animation:false, //charts3 no
  97. label: {
  98. normal: {
  99. show: false
  100. },
  101. },
  102. data: [50, 20, 40]
  103. },
  104. {
  105. name: "",
  106. type: 'gauge',
  107. splitNumber: 30, //刻度数量
  108. min: 0,
  109. max: 100,
  110. radius: '73%', //图表尺寸
  111. center: ['50%', '50%'],
  112. startAngle: 90,
  113. endAngle: -269.9999,
  114. axisLine: {
  115. show: false,
  116. lineStyle: {
  117. width: 0,
  118. shadowBlur: 0,
  119. color: [
  120. [1, '#0dc2fe']
  121. ]
  122. }
  123. },
  124. axisTick: {
  125. show: false,
  126. lineStyle: {
  127. color: 'auto',
  128. width: 2
  129. },
  130. length: 20,
  131. splitNumber: 5
  132. },
  133. splitLine: {
  134. show: true,
  135. length: 32,
  136. lineStyle: {
  137. color: 'auto',
  138. }
  139. },
  140. axisLabel: {
  141. show: false
  142. },
  143. pointer: { //仪表盘指针
  144. show: 0,
  145. },
  146. detail: {
  147. show: 0,
  148. },
  149. },
  150. {
  151. name: '统计',
  152. type: 'gauge',
  153. splitNumber: 30, //刻度数量
  154. min: 0,
  155. max: 100,
  156. radius: '68%', //图表尺寸
  157. center: ['50%', '50%'],
  158. startAngle: 90,
  159. endAngle: -269.9999,
  160. axisLine: {
  161. show: true,
  162. lineStyle: {
  163. width: 0,
  164. shadowBlur: 0,
  165. color: [
  166. [0, '#0dc2fe'],
  167. [1, '#0dc2fe']
  168. ]
  169. }
  170. },
  171. axisTick: {
  172. show: true,
  173. lineStyle: {
  174. color: '#0dc2fe',
  175. width: 2
  176. },
  177. length: 20,
  178. splitNumber: 5
  179. },
  180. splitLine: {
  181. show: true,
  182. length: 20,
  183. lineStyle: {
  184. color: '#0dc2fe',
  185. }
  186. },
  187. axisLabel: {
  188. show: false
  189. },
  190. pointer: { //仪表盘指针
  191. show: 0,
  192. },
  193. detail: {
  194. borderColor: '#fff',
  195. shadowColor: '#fff', //默认透明
  196. shadowBlur: 2,
  197. offsetCenter: [0, '0%'], // x, y,单位px
  198. textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  199. color: '#fff',
  200. fontSize: 50,
  201. },
  202. formatter: '{value}'
  203. },
  204. data: [{
  205. name: "",
  206. value: 2020
  207. }]
  208. },
  209. {
  210. type: 'pie',
  211. zlevel: 20,
  212. silent: true,
  213. radius: ['60%', '59%'],
  214. hoverAnimation: false,
  215. color: '#2dc0c9',
  216. // animation:false,
  217. data: [1],
  218. labelLine: {
  219. normal: {
  220. show: false
  221. }
  222. }
  223. },
  224. {
  225. name: '中间环形图',
  226. type: 'pie',
  227. radius: ['35%', '55%'],
  228. avoidLabelOverlap: false,
  229. hoverAnimation: false,
  230. itemStyle: {
  231. normal: {
  232. color: '#80ADD2',
  233. borderColor: '#3D4268',
  234. }
  235. },
  236. label: {
  237. normal: {
  238. show: false,
  239. position: 'center',
  240. },
  241. emphasis: {
  242. show: true,
  243. textStyle: {
  244. fontSize: '30',
  245. fontWeight: 'bold'
  246. }
  247. }
  248. },
  249. labelLine: {
  250. normal: {
  251. show: false
  252. }
  253. },
  254. data: [
  255. 25, 25, 25, 25, 25, 25
  256. ]
  257. },
  258. ]
  259. };
  260. function _pie1() {
  261. let dataArr = [];
  262. for (var i = 0; i < 8; i++) {
  263. dataArr.push({
  264. name: (i + 1).toString(),
  265. value: 20,
  266. itemStyle: {
  267. normal: {
  268. color: "rgba(88,142,197,0.4)",
  269. borderWidth: 0,
  270. borderColor: "rgba(0,0,0,0)"
  271. }
  272. }
  273. })
  274. }
  275. return dataArr
  276. }
  277. function _pie2() {
  278. let dataArr = [];
  279. for (var i = 0; i < 8; i++) {
  280. if (i % 2 === 0) {
  281. dataArr.push({
  282. name: (i + 1).toString(),
  283. value: 25,
  284. itemStyle: {
  285. normal: {
  286. color: "rgba(88,142,197,0.5)",
  287. borderWidth: 0,
  288. borderColor: "rgba(0,0,0,0)"
  289. }
  290. }
  291. })
  292. } else {
  293. dataArr.push({
  294. name: (i + 1).toString(),
  295. value: 20,
  296. itemStyle: {
  297. normal: {
  298. color: "rgba(0,0,0,0)",
  299. borderWidth: 0,
  300. borderColor: "rgba(0,0,0,0)"
  301. }
  302. }
  303. })
  304. }
  305. }
  306. return dataArr
  307. }
  308. function _pie3() {
  309. let dataArr = [];
  310. for (var i = 0; i < 100; i++) {
  311. if (i % 2 === 0) {
  312. dataArr.push({
  313. name: (i + 1).toString(),
  314. value: 25,
  315. itemStyle: {
  316. normal: {
  317. color: "rgb(126,190,255)",
  318. borderWidth: 0,
  319. borderColor: "rgba(0,0,0,0)"
  320. }
  321. }
  322. })
  323. } else {
  324. dataArr.push({
  325. name: (i + 1).toString(),
  326. value: 20,
  327. itemStyle: {
  328. normal: {
  329. color: "rgba(0,0,0,0)",
  330. borderWidth: 0,
  331. borderColor: "rgba(0,0,0,0)"
  332. }
  333. }
  334. })
  335. }
  336. }
  337. return dataArr
  338. }
  339. function _pieData(data) {
  340. let _data = data;
  341. let dataArr = [];
  342. for (var i = 0; i < 5; i++) {
  343. if (i === 2) {
  344. let dt = (data[0].unit) ? 25 : (Number(data[0].value));
  345. dataArr.push({
  346. name: (i + 1).toString(),
  347. value: dt,
  348. itemStyle: {
  349. normal: {
  350. color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
  351. offset: 0,
  352. color: 'rgb(147,187,216)'
  353. }, {
  354. offset: 1,
  355. color: '#588ec5'
  356. }]),
  357. borderWidth: 0,
  358. borderColor: "rgba(0,0,0,0.4)"
  359. }
  360. }
  361. })
  362. } else {
  363. let dta = (data[0].unit) ? 25 : (1 - Number(data[0].value)) / 4;
  364. dataArr.push({
  365. name: (i + 1).toString(),
  366. value: dta,
  367. itemStyle: {
  368. normal: {
  369. color: "rgba(0,0,0,0)",
  370. borderWidth: 0,
  371. borderColor: "rgba(0,0,0,0)"
  372. }
  373. }
  374. })
  375. }
  376. }
  377. //console.log(dataArr)
  378. return dataArr
  379. }
  380. //鼠标事件:'click','dblclick','mousedown','mouseup','mouseover','mouseout','globalout'。
  381. myChart.on('mouseover', function(params) {
  382. stopTimer();
  383. });
  384. myChart.on('mouseout', function(params) {
  385. startTimer();
  386. });
  387. var timer;
  388. function doing() {
  389. let option = myChart.getOption();
  390. option.series[3].startAngle = option.series[3].startAngle - 1;
  391. option.series[6].data[0].value = option.series[6].data[0].value + 1;
  392. myChart.setOption(option);
  393. }
  394. function startTimer() {
  395. timer = setInterval(doing, 100);
  396. }
  397. function stopTimer() {
  398. clearInterval(timer);
  399. xzTimer = null;
  400. }
  401. setTimeout(startTimer, 500);