dynamicLineBar.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="ECharts">
  8. <meta name="author" content="kener.linfeng@gmail.com">
  9. <title>ECharts · Example</title>
  10. <link rel="shortcut icon" href="../asset/ico/favicon.png">
  11. <link href="../asset/css/font-awesome.min.css" rel="stylesheet">
  12. <link href="../asset/css/bootstrap.css" rel="stylesheet">
  13. <link href="../asset/css/carousel.css" rel="stylesheet">
  14. <link href="../asset/css/echartsHome.css" rel="stylesheet">
  15. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <script src="./www/js/echarts.js"></script>
  21. <script src="../asset/js/codemirror.js"></script>
  22. <script src="../asset/js/javascript.js"></script>
  23. <link href="../asset/css/codemirror.css" rel="stylesheet">
  24. <link href="../asset/css/monokai.css" rel="stylesheet">
  25. </head>
  26. <body>
  27. <!-- Fixed navbar -->
  28. <div class="navbar navbar-default navbar-fixed-top" role="navigation" id="head"></div>
  29. <div class="container-fluid">
  30. <div class="row-fluid example">
  31. <div id="sidebar-code" class="col-md-4">
  32. <div class="well sidebar-nav">
  33. <div class="nav-header"><a href="#" onclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div>
  34. <textarea id="code" name="code">
  35. option = {
  36. title : {
  37. text: '动态数据',
  38. subtext: '纯属虚构'
  39. },
  40. tooltip : {
  41. trigger: 'axis'
  42. },
  43. legend: {
  44. data:['最新成交价', '预购队列']
  45. },
  46. toolbox: {
  47. show : true,
  48. feature : {
  49. mark : {show: true},
  50. dataView : {show: true, readOnly: false},
  51. magicType : {show: true, type: ['line', 'bar']},
  52. restore : {show: true},
  53. saveAsImage : {show: true}
  54. }
  55. },
  56. dataZoom : {
  57. show : false,
  58. start : 0,
  59. end : 100
  60. },
  61. xAxis : [
  62. {
  63. type : 'category',
  64. boundaryGap : true,
  65. data : (function (){
  66. var now = new Date();
  67. var res = [];
  68. var len = 10;
  69. while (len--) {
  70. res.unshift(now.toLocaleTimeString().replace(/^\D*/,''));
  71. now = new Date(now - 2000);
  72. }
  73. return res;
  74. })()
  75. },
  76. {
  77. type : 'category',
  78. boundaryGap : true,
  79. data : (function (){
  80. var res = [];
  81. var len = 10;
  82. while (len--) {
  83. res.push(len + 1);
  84. }
  85. return res;
  86. })()
  87. }
  88. ],
  89. yAxis : [
  90. {
  91. type : 'value',
  92. scale: true,
  93. name : '价格',
  94. boundaryGap: [0.2, 0.2]
  95. },
  96. {
  97. type : 'value',
  98. scale: true,
  99. name : '预购量',
  100. boundaryGap: [0.2, 0.2]
  101. }
  102. ],
  103. series : [
  104. {
  105. name:'预购队列',
  106. type:'bar',
  107. xAxisIndex: 1,
  108. yAxisIndex: 1,
  109. data:(function (){
  110. var res = [];
  111. var len = 10;
  112. while (len--) {
  113. res.push(Math.round(Math.random() * 1000));
  114. }
  115. return res;
  116. })()
  117. },
  118. {
  119. name:'最新成交价',
  120. type:'line',
  121. data:(function (){
  122. var res = [];
  123. var len = 10;
  124. while (len--) {
  125. res.push((Math.random()*10 + 5).toFixed(1) - 0);
  126. }
  127. return res;
  128. })()
  129. }
  130. ]
  131. };
  132. var lastData = 11;
  133. var axisData;
  134. clearInterval(timeTicket);
  135. timeTicket = setInterval(function (){
  136. lastData += Math.random() * ((Math.round(Math.random() * 10) % 2) == 0 ? 1 : -1);
  137. lastData = lastData.toFixed(1) - 0;
  138. axisData = (new Date()).toLocaleTimeString().replace(/^\D*/,'');
  139. // 动态数据接口 addData
  140. myChart.addData([
  141. [
  142. 0, // 系列索引
  143. Math.round(Math.random() * 1000), // 新增数据
  144. true, // 新增数据是否从队列头部插入
  145. false // 是否增加队列长度,false则自定删除原有数据,队头插入删队尾,队尾插入删队头
  146. ],
  147. [
  148. 1, // 系列索引
  149. lastData, // 新增数据
  150. false, // 新增数据是否从队列头部插入
  151. false, // 是否增加队列长度,false则自定删除原有数据,队头插入删队尾,队尾插入删队头
  152. axisData // 坐标轴标签
  153. ]
  154. ]);
  155. }, 2100);
  156. </textarea>
  157. </div><!--/.well -->
  158. </div><!--/span-->
  159. <div id="graphic" class="col-md-8">
  160. <div id="main" class="main"></div>
  161. <div>
  162. <button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
  163. <span class="text-primary">切换主题</span>
  164. <select id="theme-select"></select>
  165. <span id='wrong-message' style="color:red"></span>
  166. </div>
  167. </div><!--/span-->
  168. </div><!--/row-->
  169. </div><!--/.fluid-container-->
  170. <footer id="footer"></footer>
  171. <!-- Le javascript
  172. ================================================== -->
  173. <!-- Placed at the end of the document so the pages load faster -->
  174. <script src="../asset/js/jquery.min.js"></script>
  175. <script type="text/javascript" src="../asset/js/echartsHome.js"></script>
  176. <script src="../asset/js/bootstrap.min.js"></script>
  177. <script type="text/javascript">var timeTicket;</script>
  178. <script src="../asset/js/echartsExample.js"></script>
  179. </body>
  180. </html>