treemap-option.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Option View</title>
  6. <script src="lib/esl.js"></script>
  7. <script src="lib/config.js"></script>
  8. <style type="text/css">
  9. body {
  10. margin: 0;
  11. }
  12. html, body, #option-view-chart {
  13. height: 100%;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div id="option-view-chart"></div>
  19. <script src="./lib/jquery.min.js"></script>
  20. <script>
  21. var echarts;
  22. var formatUtil;
  23. var chart;
  24. require([
  25. 'echarts'
  26. // 'echarts/util/format',
  27. // 'echarts/component/tooltip',
  28. // 'echarts/component/legend',
  29. // 'echarts/chart/treemap'
  30. ], function (ec) {
  31. echarts = ec;
  32. formatUtil = echarts.format;
  33. chart = echarts.init($('#option-view-chart')[0]);
  34. chart.showLoading();
  35. $.getJSON('./data/option-view.json', initEcharts);
  36. });
  37. function convert(source, target, basePath) {
  38. for (var key in source) {
  39. var path = basePath ? (basePath + '.' + key) : key;
  40. if (key.match(/^\$/)) {
  41. }
  42. else {
  43. target.children = target.children || [];
  44. var child = {
  45. name: path
  46. };
  47. target.children.push(child);
  48. convert(source[key], child, path);
  49. }
  50. }
  51. target.value = source.$count || 1;
  52. }
  53. function initEcharts(rawData) {
  54. chart.hideLoading();
  55. var data = {};
  56. convert(rawData, data, '');
  57. chart.setOption({
  58. title: {
  59. text: '配置项查询分布',
  60. left: 'center'
  61. },
  62. tooltip: {},
  63. series: [{
  64. name: 'option',
  65. type: 'treemap',
  66. visibleMin: 300,
  67. // animationDurationUpdate: 2000,
  68. // data: data.children,
  69. data: [
  70. {
  71. name: 'a',
  72. value: 10,
  73. label: {
  74. normal: {
  75. formatter: function (params) {
  76. console.log(params);
  77. return 'from label formatter';
  78. }
  79. }
  80. },
  81. children: [
  82. {
  83. name: 'a1',
  84. value: 11,
  85. children: [
  86. {
  87. name: 'a11',
  88. value: 111,
  89. },
  90. {
  91. name: 'a111',
  92. value: 1111
  93. },
  94. {
  95. name: 'a112',
  96. value: 1111
  97. },
  98. {
  99. name: 'a113',
  100. value: 111
  101. },
  102. {
  103. name: 'a114',
  104. value: 111
  105. },
  106. {
  107. name: 'a115',
  108. value: 1100
  109. }
  110. ]
  111. }
  112. ]
  113. },
  114. {
  115. name: 'b',
  116. value: 6,
  117. children: [
  118. {
  119. name: 'b1',
  120. value: 15,
  121. chidren: [
  122. {
  123. name: 'b11',
  124. value: 120
  125. }
  126. ]
  127. }
  128. ]
  129. }
  130. ],
  131. leafDepth: 1,
  132. nodeClick: 'link',
  133. itemStyle: {
  134. // normal: {
  135. // gapWidth: 1,
  136. // borderWidth: 1
  137. // }
  138. },
  139. levels: [
  140. {
  141. itemStyle: {
  142. normal: {
  143. borderColor: '#333',
  144. borderWidth: 4,
  145. gapWidth: 2
  146. }
  147. }
  148. },
  149. {
  150. itemStyle: {
  151. normal: {
  152. borderColor: '#aaa',
  153. gapWidth: 2,
  154. borderWidth: 2
  155. }
  156. },
  157. colorSaturation: [0.2, 0.7]
  158. }
  159. ]
  160. }]
  161. });
  162. }
  163. $(window).resize(function () {
  164. chart && chart.resize();
  165. })
  166. </script>
  167. </body>
  168. </html>