dataZoom-dynamic.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/testHelper.js"></script>
  8. <meta name="viewport" content="width=device-width, initial-scale=1" />
  9. <link rel="stylesheet" href="lib/reset.css">
  10. </head>
  11. <body>
  12. <style>
  13. h1 {
  14. line-height: 60px;
  15. height: 60px;
  16. background: #ddd;
  17. text-align: center;
  18. font-weight: bold;
  19. font-size: 14px;
  20. }
  21. .chart {
  22. height: 350px;
  23. }
  24. </style>
  25. <h1>Shift</h1>
  26. <div class="chart" id="shift"></div>
  27. <h1>Range stick to value</h1>
  28. <div class="chart" id="value"></div>
  29. <script>
  30. var echarts;
  31. var chart;
  32. var myChart;
  33. require([
  34. 'echarts'
  35. // 'echarts/chart/line',
  36. // 'echarts/chart/bar',
  37. // 'echarts/component/legend',
  38. // 'echarts/component/grid',
  39. // 'echarts/component/tooltip',
  40. // 'echarts/component/toolbox',
  41. // 'echarts/component/dataZoom',
  42. // 'echarts/component/markLine'
  43. ], function (ec) {
  44. echarts = ec;
  45. var app = {};
  46. var option = {
  47. title : {
  48. text: '动态数据',
  49. subtext: '纯属虚构'
  50. },
  51. tooltip : {
  52. trigger: 'axis'
  53. },
  54. legend: {
  55. data:['最新成交价']
  56. },
  57. toolbox: {
  58. show : true,
  59. feature : {
  60. dataZoom : {
  61. yAxisIndex: false
  62. },
  63. }
  64. },
  65. dataZoom : [{
  66. type: 'inside',
  67. start : 0,
  68. end : 100
  69. },
  70. {
  71. type: 'slider',
  72. start : 0,
  73. end : 100
  74. }
  75. ],
  76. xAxis : [
  77. {
  78. type : 'value',
  79. scale: true
  80. }
  81. ],
  82. yAxis : [
  83. {
  84. type : 'value',
  85. scale: true,
  86. name : '预购量',
  87. max: 1200,
  88. min: 0,
  89. boundaryGap: [0.2, 0.2]
  90. }
  91. ],
  92. series : [
  93. {
  94. name:'最新成交价',
  95. type:'line',
  96. data:(function (){
  97. var res = [];
  98. var len = 0;
  99. while (len < 10) {
  100. var n = [
  101. len,
  102. (Math.random()*10 + 5).toFixed(1)
  103. ];
  104. res.push({name: n[0], value: n});
  105. len++;
  106. }
  107. return res;
  108. })(),
  109. animation: true,
  110. animationDurationUpdate: 500,
  111. animationEasing: 'linear',
  112. animationEasingUpdate: 'linear'
  113. }
  114. ]
  115. };
  116. var myChart = testHelper.createChart(echarts, 'shift', option);
  117. if (!myChart) {
  118. return;
  119. }
  120. clearInterval(app.timeTicket);
  121. app.count = 11;
  122. app.timeTicket = setInterval(function (){
  123. var data0 = option.series[0].data;
  124. data0.shift();
  125. var lastData = data0[data0.length - 1].value;
  126. var x = [lastData[0] + 1, Math.round(Math.random() * 1000)];
  127. data0.push({name: x[0], value: x});
  128. myChart.setOption({series: option.series});
  129. }, 2100);
  130. });
  131. </script>
  132. <script>
  133. var echarts;
  134. var chart;
  135. var myChart;
  136. require([
  137. 'echarts'
  138. // 'echarts/chart/line',
  139. // 'echarts/chart/bar',
  140. // 'echarts/component/legend',
  141. // 'echarts/component/grid',
  142. // 'echarts/component/tooltip',
  143. // 'echarts/component/dataZoom',
  144. // 'echarts/component/markLine'
  145. ], function (ec) {
  146. echarts = ec;
  147. var app = {};
  148. var option = {
  149. title : {
  150. text: '动态数据',
  151. subtext: '纯属虚构'
  152. },
  153. tooltip : {
  154. trigger: 'axis'
  155. },
  156. legend: {
  157. data:['最新成交价']
  158. },
  159. toolbox: {
  160. show : true,
  161. feature : {
  162. dataZoom : {
  163. yAxisIndex: false
  164. },
  165. }
  166. },
  167. dataZoom : [{
  168. type: 'inside',
  169. start : 0,
  170. endValue : 8,
  171. rangeMode: ['value', 'value']
  172. },
  173. {
  174. type: 'slider',
  175. start : 0,
  176. endValue : 8,
  177. rangeMode: ['value', 'value']
  178. }
  179. ],
  180. xAxis : [
  181. {
  182. type : 'value',
  183. scale: true
  184. }
  185. ],
  186. yAxis : [
  187. {
  188. type : 'value',
  189. scale: true,
  190. name : '预购量',
  191. max: 1200,
  192. min: 0,
  193. boundaryGap: [0.2, 0.2]
  194. }
  195. ],
  196. series : [
  197. {
  198. name:'最新成交价',
  199. type:'line',
  200. data:(function (){
  201. var res = [];
  202. var len = 0;
  203. while (len < 10) {
  204. var n = [
  205. len,
  206. (Math.random()*10 + 5).toFixed(1)
  207. ];
  208. res.push({name: n[0], value: n});
  209. len++;
  210. }
  211. return res;
  212. })(),
  213. animation: true,
  214. animationDurationUpdate: 500,
  215. animationEasing: 'linear',
  216. animationEasingUpdate: 'linear'
  217. }
  218. ]
  219. };
  220. var myChart = testHelper.createChart(echarts, 'value', option);
  221. if (!myChart) {
  222. return;
  223. }
  224. clearInterval(app.timeTicket);
  225. app.count = 11;
  226. app.timeTicket = setInterval(function (){
  227. var data0 = option.series[0].data;
  228. var lastData = data0[data0.length - 1].value;
  229. var x = [lastData[0] + 1, Math.round(Math.random() * 1000)];
  230. data0.push({name: x[0], value: x});
  231. myChart.setOption({series: option.series});
  232. app.count++;
  233. if (app.count > 300) {
  234. clearInterval(app.timeTicket);
  235. }
  236. }, 2100);
  237. });
  238. </script>
  239. </body>
  240. </html>