treemap-option2.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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-view2.json', initEcharts);
  36. });
  37. function initEcharts(rawData) {
  38. chart.hideLoading();
  39. function convert(source, target, basePath) {
  40. for (var key in source) {
  41. var path = basePath ? (basePath + '.' + key) : key;
  42. if (key.match(/^\$/)) {
  43. }
  44. else {
  45. target.children = target.children || [];
  46. var child = {
  47. name: path
  48. };
  49. target.children.push(child);
  50. convert(source[key], child, path);
  51. }
  52. }
  53. if (!target.children) {
  54. target.value = source.$count || 1;
  55. }
  56. else {
  57. target.children.push({
  58. name: basePath,
  59. value: source.$count
  60. });
  61. }
  62. }
  63. var data = [];
  64. convert(rawData, data, '');
  65. chart.setOption({
  66. title: {
  67. text: 'ECharts 配置项查询分布',
  68. subtext: '2016/04',
  69. left: 'leafDepth'
  70. },
  71. tooltip: {},
  72. series: [{
  73. name: 'option',
  74. type: 'treemap',
  75. visibleMin: 300,
  76. data: data.children,
  77. leafDepth: 2,
  78. levels: [
  79. {
  80. itemStyle: {
  81. normal: {
  82. borderColor: '#333',
  83. borderWidth: 1,
  84. gapWidth: 1
  85. }
  86. }
  87. },
  88. {
  89. colorSaturation: [0.3, 0.6],
  90. itemStyle: {
  91. normal: {
  92. borderColor: '#fff',
  93. borderWidth: 1
  94. }
  95. }
  96. }
  97. ]
  98. }]
  99. });
  100. }
  101. $(window).resize(function () {
  102. chart && chart.resize();
  103. })
  104. </script>
  105. </body>
  106. </html>