custom-children-remove.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="lib/esl.js"></script>
  6. <script src="lib/config.js"></script>
  7. <script src="lib/jquery.min.js"></script>
  8. <script src="lib/facePrint.js"></script>
  9. <script src="lib/testHelper.js"></script>
  10. <meta name="viewport" content="width=device-width, initial-scale=1" />
  11. <link rel="stylesheet" href="lib/reset.css">
  12. </head>
  13. <body>
  14. <style>
  15. h1 {
  16. line-height: 60px;
  17. height: 60px;
  18. background: #146402;
  19. text-align: center;
  20. font-weight: bold;
  21. color: #eee;
  22. font-size: 14px;
  23. }
  24. .chart {
  25. height: 500px;
  26. }
  27. </style>
  28. <div class="chart" id="main"></div>
  29. <script>
  30. var echarts;
  31. var chart;
  32. var myChart;
  33. var groupCategories = [];
  34. var groupColors = [];
  35. require([
  36. 'echarts'
  37. // 'echarts/chart/line',
  38. // 'echarts/chart/bar',
  39. // 'echarts/chart/pie',
  40. // 'echarts/chart/scatter',
  41. // 'echarts/chart/custom',
  42. // 'echarts/chart/parallel',
  43. // 'echarts/chart/radar',
  44. // 'echarts/component/grid',
  45. // 'echarts/component/polar',
  46. // 'echarts/component/geo',
  47. // 'echarts/component/singleAxis',
  48. // 'echarts/component/legend',
  49. // 'echarts/component/tooltip',
  50. // 'echarts/component/toolbox',
  51. // 'echarts/component/visualMap',
  52. // 'echarts/component/dataZoom'
  53. ], function (ec) {
  54. echarts = ec;
  55. chart = myChart = echarts.init(document.getElementById('main'));
  56. var data = [
  57. {name:'广州', value: 50},
  58. {name:'深圳', value: 72},
  59. {name:'珠海', value: 30},
  60. {name:'佛山', value: 38},
  61. {name:'杭州', value: 42},
  62. {name:'舟山', value: 32},
  63. {name:'宁波', value: 52}
  64. ];
  65. option = {
  66. tooltip : {
  67. trigger: 'item'
  68. },
  69. legend: {
  70. data:['广州','深圳','珠海','佛山','杭州','舟山','宁波'],
  71. top: 0,
  72. left: 'center'
  73. },
  74. xAxis : [
  75. {
  76. type : 'category',
  77. data : [0],
  78. axisTick: {show: false},
  79. axisLabel: {show: false}
  80. },
  81. ],
  82. yAxis : [
  83. {
  84. type : 'value'
  85. }
  86. ],
  87. series : echarts.util.map(data, function (item) {
  88. return {
  89. name: item.name,
  90. type: 'bar',
  91. label: {
  92. normal: {
  93. show: true,
  94. position: 'bottom',
  95. formatter: function (param) {
  96. return param.seriesName;
  97. }
  98. }
  99. },
  100. data: [item.value]
  101. }
  102. }).concat([{
  103. type: 'custom',
  104. renderItem: renderProvinceName,
  105. data: [0]
  106. }])
  107. };
  108. function renderProvinceName(param, api) {
  109. var currentSeriesIndices = api.currentSeriesIndices();
  110. currentSeriesIndices.pop(); // remove custom series;
  111. var barLayout = api.barLayout({
  112. barGap: '30%', barCategoryGap: '20%', count: currentSeriesIndices.length
  113. });
  114. var nameTexts = echarts.util.map(currentSeriesIndices, function (serIdx, index) {
  115. var point = api.coord([0, 0]);
  116. point[0] += barLayout[index].offsetCenter;
  117. point[1] = api.getHeight() - 20;
  118. return {
  119. position: point,
  120. name: serIdx,
  121. type: 'circle',
  122. shape: {
  123. cx: 0, cy: 0, r: 10
  124. },
  125. style: {
  126. text: serIdx,
  127. fill: '#333',
  128. stroke: null
  129. }
  130. };
  131. });
  132. return {
  133. type: 'group',
  134. diffChildrenByName: true,
  135. children: nameTexts
  136. };
  137. }
  138. chart.setOption(option);
  139. });
  140. </script>
  141. </body>
  142. </html>