• Echarts绘制Tree树图的涟漪效果effectScatter


    1. 问题描述

    Echarts绘制图表是支持涟漪效果的,但是搜了材料,有地图、折线图、散点图等,不支持树图。

    本文方法实现了一种可以任意Echarts图的涟漪效果

    2. 效果展示

    将树图的一级节点全部加上涟漪效果:如下

     3. 解决思路

    3.1 找出问题

    Echarts配置项中明确支持涟漪效果的图表,不支持其他图表

     3.2 创新

    领导说了,效果我就想要那种,画不出来滚蛋!

    叠加!叠加!叠加

    4. 解决过程

    4.1 绘制树图

    这个简单可以参考官网Examples - Apache ECharts

     如图,原始图像

    4.2 绘制xy图--类似棋盘

    1. xAxis: [{
    2. data:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
    3. splitLine: {
    4. show: false,
    5. },
    6. axisLabel: {
    7. show: false,
    8. },
    9. axisLine: {
    10. show: false,
    11. },
    12. axisTick: {
    13. show: false,
    14. }
    15. }],
    16. yAxis: [{
    17. data:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
    18. splitLine: {
    19. show: false,
    20. },
    21. axisLabel: {
    22. show: false,
    23. },
    24. axisLine: {
    25. show: false,
    26. },
    27. axisTick: {
    28. show: false,
    29. }
    30. }],

            这里绘制的是30*30棋盘,如果棋盘的点和你想绘制闪烁点的位置对应不上,可以绘制40*40,50*50......加大像素点密度

    4.3 点点对应

            在绘制的过程中,将splitLine、axisLabel、axisLine、axisTick都设置为true,方便点点对应,如下图:下图是最开始的10*10,对应不上,后改为30*30

             一般还有一个问题树图和xy图没叠加到一起,需要设置grid,grid应该也是两个,本实例中只写了一个,默认对应代码写在上面的xy图,即调整xy图的grid去适配树图。

    xy图的data如下

    data:[{value:[2,15],symbolSize:12},{value:[11,0],symbolSize:8},{value:[11,2],symbolSize:8},{value:[11,4],symbolSize:8},{value:[11,6],symbolSize:8},{value:[11,8],symbolSize:8},{value:[11,12],symbolSize:8},{value:[11,16],symbolSize:8},{value:[11,19],symbolSize:8},{value:[11,23],symbolSize:8},{value:[11,26],symbolSize:8},{value:[11,30],symbolSize:8}],

    这种方法解决了任何图像实现涟漪效果的叠加

    4.4 总体代码

    1. const data = {
    2. name: 'Buoy',
    3. children: [
    4. {
    5. name: 'CTD',
    6. children: [
    7. {
    8. name: 'temperature',
    9. value: 60
    10. },
    11. {
    12. name: 'pressure',
    13. value: 60
    14. },
    15. {
    16. name: 'salinity',
    17. value: 60
    18. },
    19. ]
    20. },
    21. {
    22. name: 'ADCP',
    23. children: [
    24. {
    25. name: 'velocityU',
    26. value: 60
    27. },
    28. {
    29. name: 'velocityV',
    30. value: 60
    31. },
    32. {
    33. name: 'velocityW',
    34. value: 60
    35. }
    36. ]
    37. },
    38. {
    39. name: 'Nitrate',
    40. children: [
    41. {
    42. name: 'nitrate',
    43. value: 120
    44. }
    45. ]
    46. },
    47. {
    48. name: 'Triplet',
    49. children: [
    50. {
    51. name: 'FDOM',
    52. value: 1
    53. },
    54. {
    55. name: 'chlorophyll',
    56. value: 1
    57. },
    58. {
    59. name: 'turbidity',
    60. value: 1
    61. }
    62. ]
    63. },{
    64. name:'PAR',
    65. children:[
    66. {
    67. name:'par',
    68. value: 1
    69. }
    70. ]
    71. },{
    72. name:'Meteorological',
    73. children:[
    74. {
    75. name:'airTemperature',
    76. value: 1
    77. },{
    78. name:'atmosphere',
    79. value: 1
    80. },{
    81. name:'windSpeed',
    82. value: 1
    83. },{
    84. name:'windDirection',
    85. value: 1
    86. }
    87. ]
    88. },{
    89. name:' AtmosphericPressure',
    90. children:[{
    91. name:'atmospheric pressure',
    92. value:1
    93. }
    94. ]
    95. },{
    96. name:'Methane',
    97. //value:1,
    98. children:[{
    99. name:'methane',
    100. value:5
    101. }
    102. ]
    103. },{
    104. name:'Carbon Dioxide',
    105. //value:1,
    106. children:[{
    107. name:'carbon dioxide',
    108. value:1
    109. }
    110. ]
    111. },{
    112. name:'Dissolved Oxygen',
    113. //value:1,
    114. children:[{
    115. name:'dissolved oxygen',
    116. value:60
    117. }
    118. ]
    119. },
    120. {
    121. name:'pH',
    122. //value:1,
    123. children:[{
    124. name:'pH',
    125. value:10
    126. }
    127. ]
    128. }
    129. ],
    130. }
    131. const option = {
    132. tooltip: {
    133. trigger: 'item',
    134. triggerOn: 'mousemove'
    135. },
    136. grid:{
    137. top: '8%',
    138. left: '5%',
    139. right: '12%',
    140. height: '87%'
    141. },
    142. xAxis: [{
    143. data:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
    144. splitLine: {
    145. show: false,
    146. },
    147. axisLabel: {
    148. show: false,
    149. },
    150. axisLine: {
    151. show: false,
    152. },
    153. axisTick: {
    154. show: false,
    155. }
    156. }],
    157. yAxis: [{
    158. data:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
    159. splitLine: {
    160. show: false,
    161. },
    162. axisLabel: {
    163. show: false,
    164. },
    165. axisLine: {
    166. show: false,
    167. },
    168. axisTick: {
    169. show: false,
    170. }
    171. }],
    172. series: [
    173. {
    174. type: 'tree',
    175. data: [data],
    176. left: '10%',
    177. right: '40%',
    178. top: '3%',
    179. bottom: '3%',
    180. symbolSize:6,
    181. label: {
    182. position: 'left',
    183. verticalAlign: 'middle',
    184. align: 'right',
    185. fontSize: 12,
    186. fontWeight: 300,
    187. color: '#32ffc7',
    188. },
    189. leaves: {
    190. label: {
    191. position: 'right',
    192. rotate: 0,
    193. verticalAlign: 'middle',
    194. padding:[2,2,2,2],
    195. lineHeight:15,
    196. align: 'left',
    197. color: '#fff',
    198. formatter: '{b}: {c}',
    199. distance: 20,
    200. },
    201. itemStyle: {
    202. color: '#12c9f6',
    203. borderWidth: 10,
    204. borderColor: '#FFFFFF',
    205. borderType: 'solid'
    206. }
    207. },
    208. animationDurationUpdate: 750,
    209. emphasis: {
    210. focus: 'descendant'
    211. },
    212. expandAndCollapse:true,
    213. animationDuration:550,
    214. },
    215. {
    216. type:'effectScatter',
    217. data:[{value:[2,15],symbolSize:12},{value:[11,0],symbolSize:8},{value:[11,2],symbolSize:8},{value:[11,4],symbolSize:8},{value:[11,6],symbolSize:8},{value:[11,8],symbolSize:8},{value:[11,12],symbolSize:8},{value:[11,16],symbolSize:8},{value:[11,19],symbolSize:8},{value:[11,23],symbolSize:8},{value:[11,26],symbolSize:8},{value:[11,30],symbolSize:8}],
    218. showEffectOn: 'render',
    219. rippleEffect: {
    220. // 波纹的绘制方式,可选'stroke'和'fill'
    221. brushType: 'fill',
    222. number:3,
    223. scale:3
    224. },
    225. hoverAnimation: true,
    226. itemStyle: {
    227. normal: {
    228. color: '#16D762',
    229. shadowBlur: 30,
    230. shadowColor: '#16D762'
    231. }
    232. },
    233. zlevel:1
    234. }
    235. ]
    236. };

  • 相关阅读:
    如何将项目(工程/代码)文件上传到gitee?(注意一下,有几个坑)
    python_基础语法(列表、列表基本操作)
    Day15-尚品汇-vee-validate
    【英语:基础高阶_学术写作训练】J5.学术写作篇章分析
    组管理和权限管理
    【无标题】
    新手如何练习SQL?|掌握
    关于python字符串
    Linux引入中saltstack介绍与使用
    云原生【1】:docker 常用知识总结
  • 原文地址:https://blog.csdn.net/u010763324/article/details/127667750