dataZoom-action.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1" />
  5. <script src="../dist/echarts.js"></script>
  6. <script src="lib/facePrint.js"></script>
  7. <script src="lib/jquery.min.js"></script>
  8. <link rel="stylesheet" href="lib/reset.css" />
  9. </head>
  10. <body>
  11. <style>
  12. h1 {
  13. line-height: 60px;
  14. background: #360;
  15. text-align: center;
  16. font-weight: bold;
  17. color: #eee;
  18. font-size: 14px;
  19. margin: 0;
  20. }
  21. .chart {
  22. height: 450px;
  23. }
  24. .by-dispatch-action {
  25. padding: 5px;
  26. }
  27. </style>
  28. <div class="by-dispatch-action">
  29. by dispatchAction:
  30. <button id="change-start-value">Change Start Value</button>
  31. <button id="change-end-value">Change Start Value</button>
  32. <button id="first-focus">First Focus</button>
  33. </div>
  34. <div id="main">
  35. <div class="chart" id="chart"></div>
  36. </div>
  37. <script>
  38. $.getJSON('./data/ec-star.json', function (data) {
  39. $('#first-focus').on('click', firstFocus);
  40. $('#change-start-value').on('click', changeStartValue);
  41. $('#change-end-value').on('click', changeEndValue);
  42. var myChart = echarts.init(document.getElementById('chart'));
  43. var minStartValue = '2013-06-06';
  44. var maxEndValue = '2017-10-17';
  45. var currStartValue = '2017-01-01';
  46. var currEndValue = maxEndValue;
  47. var option = {
  48. animationDurationUpdate: 3000,
  49. tooltip: {
  50. trigger: 'axis'
  51. },
  52. xAxis: [{
  53. type: 'time',
  54. boundaryGap: false,
  55. axisLabel:{
  56. textStyle:{
  57. fontSize:14
  58. }
  59. },
  60. splitLine: {
  61. show: false,
  62. lineStyle:{
  63. color:'#f7f7f7'
  64. }
  65. }
  66. }],
  67. yAxis: [{
  68. type: 'value',
  69. name: 'Github Star',
  70. nameGap: 30,
  71. nameTextStyle: {
  72. fontSize: 20
  73. },
  74. axisLabel: {
  75. fontSize: 15
  76. },
  77. splitLine: {
  78. show: true,
  79. lineStyle:{
  80. color:'#f7f7f7'
  81. }
  82. }
  83. }],
  84. grid: {
  85. top: 120,
  86. left: 30,
  87. right: 30,
  88. bottom: 50,
  89. containLabel: true
  90. },
  91. dataZoom: [{
  92. id: 'dz',
  93. type: 'inside',
  94. xAxisIndex: 0,
  95. startValue: currStartValue,
  96. endValue: currEndValue,
  97. minValueSpan: 3600 * 24 * 1000 * 10
  98. }, {
  99. type: 'slider',
  100. xAxisIndex: 0,
  101. startValue: currStartValue,
  102. endValue: currEndValue,
  103. height: 20,
  104. handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
  105. handleSize: '90%',
  106. minSpanValue: 3600 * 24 * 1000 * 10
  107. }],
  108. visualMap: {
  109. show: false,
  110. type: 'continuous',
  111. seriesIndex: 0,
  112. min: 0,
  113. max: 23000
  114. },
  115. series: [{
  116. type: 'line',
  117. name: 'Star',
  118. lineStyle: {
  119. normal: {
  120. width: 4
  121. }
  122. },
  123. itemStyle: {
  124. normal: {
  125. borderColor: '#fff',
  126. borderWidth: 2
  127. }
  128. },
  129. showSymbol: false,
  130. symbol: 'circle',
  131. hoverAnimation: false,
  132. symbolSize: 15,
  133. sampling: 'average',
  134. // smooth: true,
  135. // symbol: 'none',
  136. data: data
  137. }]
  138. };
  139. myChart.setOption(option);
  140. $(window).resize(function() {
  141. myChart.resize();
  142. })
  143. // Control -------------------------
  144. function changeStartValue(phase) {
  145. currStartValue = '2014-09-01';
  146. myChart.dispatchAction({
  147. type: 'dataZoom',
  148. id: 'dz',
  149. startValue: currStartValue
  150. });
  151. }
  152. function changeEndValue(phase) {
  153. currEndValue = '2017-02-05';
  154. myChart.dispatchAction({
  155. type: 'dataZoom',
  156. id: 'dz',
  157. endValue: currEndValue
  158. });
  159. }
  160. function firstFocus(phase) {
  161. currStartValue = minStartValue;
  162. currEndValue = '2013-11-06';
  163. myChart.dispatchAction({
  164. type: 'dataZoom',
  165. id: 'dz',
  166. startValue: currStartValue,
  167. endValue: currEndValue
  168. });
  169. }
  170. });
  171. </script>
  172. </body>
  173. </html>