treemap-option2.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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-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. label: {
  79. normal: {
  80. formatter: '{a|{a}} {b}\n{c|{c}}',
  81. rich: {
  82. a: {
  83. // color: '#ffff00',
  84. fontSize: 18
  85. },
  86. c: {
  87. fontSize: 20,
  88. color: '#918543'
  89. }
  90. }
  91. }
  92. },
  93. levels: [
  94. {
  95. itemStyle: {
  96. normal: {
  97. borderColor: '#333',
  98. borderWidth: 1,
  99. gapWidth: 1
  100. }
  101. }
  102. },
  103. {
  104. colorSaturation: [0.3, 0.6],
  105. itemStyle: {
  106. normal: {
  107. borderColor: '#fff',
  108. borderWidth: 1
  109. }
  110. }
  111. }
  112. ]
  113. }]
  114. });
  115. chart.getZr().on('mousedown', function (params) {
  116. console.log(arguments);
  117. });
  118. }
  119. $(window).resize(function () {
  120. chart && chart.resize();
  121. });
  122. </script>
  123. </body>
  124. </html>