treemap-option.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Option View</title>
  6. <script src="esl.js"></script>
  7. <script src="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, format) {
  31. echarts = ec;
  32. formatUtil = 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. children: [
  74. {
  75. name: 'a1',
  76. value: 11,
  77. children: [
  78. {
  79. name: 'a11',
  80. value: 111,
  81. },
  82. {
  83. name: 'a111',
  84. value: 1111
  85. },
  86. {
  87. name: 'a112',
  88. value: 1111
  89. },
  90. {
  91. name: 'a113',
  92. value: 111
  93. },
  94. {
  95. name: 'a114',
  96. value: 111
  97. },
  98. {
  99. name: 'a115',
  100. value: 1100
  101. }
  102. ]
  103. }
  104. ]
  105. },
  106. {
  107. name: 'b',
  108. value: 6,
  109. children: [
  110. {
  111. name: 'b1',
  112. value: 15,
  113. chidren: [
  114. {
  115. name: 'b11',
  116. value: 120
  117. }
  118. ]
  119. }
  120. ]
  121. }
  122. ],
  123. leafDepth: 1,
  124. nodeClick: 'link',
  125. itemStyle: {
  126. // normal: {
  127. // gapWidth: 1,
  128. // borderWidth: 1
  129. // }
  130. },
  131. levels: [
  132. {
  133. itemStyle: {
  134. normal: {
  135. borderColor: '#333',
  136. borderWidth: 4,
  137. gapWidth: 2
  138. }
  139. }
  140. },
  141. {
  142. itemStyle: {
  143. normal: {
  144. borderColor: '#aaa',
  145. gapWidth: 2,
  146. borderWidth: 2
  147. }
  148. },
  149. colorSaturation: [0.2, 0.7]
  150. }
  151. ]
  152. }]
  153. });
  154. }
  155. $(window).resize(function () {
  156. chart && chart.resize();
  157. })
  158. </script>
  159. </body>
  160. </html>