dataZoom-dynamic.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="esl.js"></script>
  6. <script src="config.js"></script>
  7. <meta name="viewport" content="width=device-width, initial-scale=1" />
  8. <link rel="stylesheet" href="reset.css">
  9. </head>
  10. <body>
  11. <style>
  12. </style>
  13. <div id="main"></div>
  14. <script>
  15. var echarts;
  16. var chart;
  17. var myChart;
  18. require([
  19. 'echarts',
  20. 'echarts/chart/line',
  21. 'echarts/chart/bar',
  22. 'echarts/component/legend',
  23. 'echarts/component/grid',
  24. 'echarts/component/tooltip',
  25. 'echarts/component/dataZoom',
  26. 'echarts/component/markLine'
  27. ], function (ec) {
  28. echarts = ec;
  29. chart = myChart = echarts.init(document.getElementById('main'), null, {
  30. renderer: 'canvas'
  31. });
  32. // -------------------------------------------------------------------
  33. // -------------------------------------------------------------------
  34. // -------------------------------------------------------------------
  35. var app = {};
  36. option = {
  37. title : {
  38. text: '动态数据',
  39. subtext: '纯属虚构'
  40. },
  41. tooltip : {
  42. trigger: 'axis'
  43. },
  44. legend: {
  45. data:['最新成交价']
  46. },
  47. toolbox: {
  48. show : true,
  49. feature : {
  50. dataView : {show: true, readOnly: false},
  51. restore : {show: true},
  52. saveAsImage : {show: true}
  53. }
  54. },
  55. dataZoom : [{
  56. type: 'inside',
  57. start : 0,
  58. end : 100
  59. },
  60. {
  61. type: 'slider',
  62. start : 0,
  63. end : 100
  64. }
  65. ],
  66. xAxis : [
  67. {
  68. type : 'value',
  69. scale: true
  70. }
  71. ],
  72. yAxis : [
  73. {
  74. type : 'value',
  75. scale: true,
  76. name : '预购量',
  77. max: 1200,
  78. min: 0,
  79. boundaryGap: [0.2, 0.2]
  80. }
  81. ],
  82. series : [
  83. {
  84. name:'最新成交价',
  85. type:'line',
  86. data:(function (){
  87. var res = [];
  88. var len = 0;
  89. while (len < 10) {
  90. var n = [
  91. len,
  92. (Math.random()*10 + 5).toFixed(1)
  93. ];
  94. res.push({name: n[0], value: n});
  95. len++;
  96. }
  97. return res;
  98. })(),
  99. animation: true,
  100. animationDurationUpdate: 500,
  101. animationEasing: 'linear',
  102. animationEasingUpdate: 'linear'
  103. }
  104. ]
  105. };
  106. myChart.setOption(option);
  107. clearInterval(app.timeTicket);
  108. app.count = 11;
  109. app.timeTicket = setInterval(function (){
  110. var data0 = option.series[0].data;
  111. data0.shift();
  112. var lastData = data0[data0.length - 1].value;
  113. var x = [lastData[0] + 1, Math.round(Math.random() * 1000)];
  114. data0.push({name: x[0], value: x});
  115. myChart.setOption({series: option.series});
  116. }, 2100);
  117. // -------------------------------------------------------------------
  118. // -------------------------------------------------------------------
  119. // -------------------------------------------------------------------
  120. });
  121. </script>
  122. </body>
  123. </html>