dataZoom-cartesian-h.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="lib/esl.js"></script>
  5. <script src="lib/config.js"></script>
  6. </head>
  7. <body>
  8. <style>
  9. html, body{
  10. padding: 0;
  11. margin: 0;
  12. }
  13. #main {
  14. height: 500px;
  15. }
  16. body {
  17. margin: 0;
  18. }
  19. h3 {
  20. text-align: center;
  21. background: #eee;
  22. line-height: 30px;
  23. }
  24. </style>
  25. <h3>
  26. Check the highlighted label while data zooming.<br>
  27. Check the minSpan and maxSpan (both in slider and inside and toolbox zoom).
  28. </h3>
  29. <div id="main"></div>
  30. <script>
  31. require([
  32. 'echarts'
  33. // 'echarts/chart/bar',
  34. // 'echarts/chart/line',
  35. // 'echarts/component/legend',
  36. // 'echarts/component/grid',
  37. // 'echarts/component/axis',
  38. // 'echarts/component/dataZoom',
  39. // 'echarts/component/tooltip',
  40. // 'echarts/component/toolbox',
  41. // 'echarts/component/markPoint',
  42. // 'echarts/component/markLine'
  43. ], function (echarts) {
  44. chart = echarts.init(document.getElementById('main'), null, {
  45. });
  46. var xAxisData = [];
  47. var data1 = [];
  48. var data2 = [];
  49. var data3 = [];
  50. for (var i = 0; i < 200; i++) {
  51. var data1Val;
  52. var data2Val;
  53. var data3Val;
  54. if (Math.random() < 0.03) {
  55. data1Val = '-';
  56. data2Val = '-';
  57. data3Val = '-';
  58. }
  59. else {
  60. data1Val = (Math.random() + 0.1).toFixed(2);
  61. data2Val = (Math.random() + 1).toFixed(2);
  62. data3Val = Math.random().toFixed(2);
  63. }
  64. if (i === 10 || i === 16) {
  65. xAxisData.push({
  66. value: '类目' + i,
  67. textStyle: {
  68. fontSize: 14,
  69. color: 'red',
  70. fontWeight: 'bold'
  71. }
  72. });
  73. data1.push({
  74. value: data1Val,
  75. itemStyle: {
  76. normal: {
  77. color: 'yellow'
  78. }
  79. }
  80. });
  81. data2.push(data2Val);
  82. data3.push(data3Val);
  83. }
  84. else {
  85. xAxisData.push(i);
  86. data1.push(data1Val);
  87. data2.push(data2Val);
  88. data3.push(data3Val);
  89. }
  90. }
  91. chart.setOption({
  92. legend: {
  93. data: ['bar', 'line', 'bar3']
  94. },
  95. tooltip: {
  96. trigger: 'axis'
  97. },
  98. toolbox: {
  99. feature: {
  100. dataZoom: {
  101. show: true,
  102. xAxisIndex: false
  103. },
  104. saveAsImage: {},
  105. restore: {show: true}
  106. }
  107. },
  108. yAxis: {
  109. data: xAxisData,
  110. // inverse: true,
  111. boundaryGap: false
  112. },
  113. xAxis: {
  114. // inverse: true,
  115. // scale: true
  116. },
  117. series: [
  118. {
  119. name: 'line',
  120. type: 'line',
  121. // stack: 'all',
  122. data: data2,
  123. smooth: true
  124. },
  125. {
  126. name: 'bar3',
  127. type: 'bar',
  128. stack: 'all',
  129. data: data3,
  130. smooth: 0.1
  131. },
  132. {
  133. name: 'bar',
  134. type: 'bar',
  135. data: data1,
  136. smooth: true,
  137. stack: 'all',
  138. itemStyle: {
  139. normal: {
  140. areaStyle: {}
  141. }
  142. },
  143. markPoint: {
  144. data: [{
  145. type: 'max'
  146. }]
  147. },
  148. markLine: {
  149. data: [
  150. [{
  151. type: 'average'
  152. }, {
  153. type: 'max'
  154. }]
  155. ]
  156. }
  157. }
  158. ],
  159. dataZoom: [
  160. {
  161. show: true,
  162. startValue: 2,
  163. end: 30,
  164. borderColor: 'rgba(0,0,0,0.15)',
  165. backgroundColor: 'rgba(200,200,200,0)',
  166. yAxisIndex: 0,
  167. minValueSpan: 5,
  168. maxValueSpan: 80
  169. },
  170. {
  171. type: 'inside',
  172. startValue: 2,
  173. end: 30,
  174. yAxisIndex: 0,
  175. minSpan: 5,
  176. maxSpan: 80
  177. }
  178. ]
  179. });
  180. })
  181. </script>
  182. </body>
  183. </html>