scatter-random-stream.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1" />
  5. <script src="lib/esl.js"></script>
  6. <script src="lib/config.js"></script>
  7. <script src="lib/jquery.min.js"></script>
  8. <script src="lib/facePrint.js"></script>
  9. </head>
  10. <body>
  11. <style>
  12. html, body, #main {
  13. width: 100%;
  14. height: 100%;
  15. margin: 0;
  16. }
  17. #snapshot {
  18. position: fixed;
  19. right: 10;
  20. bottom: 10;
  21. width: 200;
  22. height: 200;
  23. background: #fff;
  24. border: 5px solid rgba(0,0,0,0.5);
  25. }
  26. </style>
  27. <div id="main"></div>
  28. <img id="snapshot"/>
  29. <script>
  30. var chunkMax = 4;
  31. var chunkCount = 0;
  32. function genData1(len, offset) {
  33. // console.profile('gen');
  34. var lngRange = [-10.781327, 131.48];
  35. var latRange = [18.252847, 52.33];
  36. var arr = new Float32Array(len * 2);
  37. var off = 0;
  38. // var data = [];
  39. for (var i = 0; i < len; i++) {
  40. var x = +Math.random() * 10;
  41. var y = +Math.sin(x) - x * (len % 2 ? 0.1 : -0.1) * Math.random() + (offset || 0) / 10;
  42. arr[off++] = x;
  43. arr[off++] = y;
  44. // data.push([
  45. // x,
  46. // y
  47. // ]);
  48. }
  49. // console.profileEnd('gen');
  50. return arr;
  51. // return data;
  52. }
  53. function genData2(count) {
  54. var lngRange = [-10.781327, 31.48];
  55. var latRange = [-18.252847, 30.33];
  56. return genData(count, lngRange, latRange);
  57. }
  58. function genData(count, lngRange, latRange) {
  59. lngRange[1] += 5;
  60. lngRange[0] -= 10;
  61. latRange[1] += 4;
  62. var lngExtent = lngRange[1] - lngRange[0];
  63. var latExtent = latRange[1] - latRange[0];
  64. var data = [];
  65. for (var i = 0; i < count; i++) {
  66. data.push([
  67. Math.random() * lngExtent + lngRange[0],
  68. Math.random() * latExtent + latRange[0],
  69. Math.random() * 1000
  70. ]);
  71. }
  72. return data;
  73. }
  74. require([
  75. 'echarts'
  76. // 'echarts/chart/map',
  77. // 'echarts/chart/scatter',
  78. // 'echarts/component/title',
  79. // 'echarts/component/legend',
  80. // 'echarts/component/geo',
  81. // 'echarts/component/visualMap',
  82. // 'echarts/component/markPoint',
  83. // 'echarts/component/tooltip'
  84. ], function (echarts) {
  85. require(['map/js/china'], function () {
  86. var chart = echarts.init(document.getElementById('main'));
  87. chart.setOption({
  88. tooltip: {},
  89. toolbox: {
  90. left: 'center',
  91. feature: {
  92. dataZoom: {}
  93. }
  94. },
  95. legend: {
  96. orient: 'vertical',
  97. left: 'left',
  98. data: ['pm2.5' /* ,'pm10' */]
  99. },
  100. // ???
  101. // visualMap: {
  102. // min: 0,
  103. // max: 1500,
  104. // left: 'left',
  105. // top: 'bottom',
  106. // text: ['High','Low'],
  107. // seriesIndex: [1, 2, 3],
  108. // inRange: {
  109. // color: ['#006edd', '#e0ffff']
  110. // },
  111. // calculable : true
  112. // },
  113. xAxis: [{
  114. }],
  115. yAxis: [{
  116. }],
  117. dataZoom: [{
  118. type: 'inside'
  119. }, {
  120. type: 'slider'
  121. }],
  122. animation: false,
  123. series : [{
  124. name: 'pm2.5',
  125. type: 'scatter',
  126. data: genData1(5e5),
  127. dimensions: ['x', 'y'],
  128. // symbol: 'rect',
  129. symbolSize: 3,
  130. // symbol: 'rect',
  131. itemStyle: {
  132. color: '#128de3',
  133. opacity: 0.4
  134. },
  135. large: true,
  136. // large: {
  137. // symbolSize: 2
  138. // },
  139. // large: function (params) {
  140. // if (params.dataCount > 30000) {
  141. // return {symbolSize: 1};
  142. // }
  143. // else if (params.dataCount > 3000) {
  144. // return {symbolSize: 5};
  145. // }
  146. // },
  147. largeThreshold: 500,
  148. progressive: 500
  149. // }, {
  150. // name: 'pm10',
  151. // type: 'scatter',
  152. // data: genData2(2001),
  153. // xAxisIndex: 0,
  154. // yAxisIndex: 0,
  155. // symbolSize: 2,
  156. // // symbol: 'rect',
  157. // itemStyle: {
  158. // normal: {
  159. // borderWidth: 0.5,
  160. // borderColor: '#e01',
  161. // color: '#128de3'
  162. // }
  163. // },
  164. // progressive: 3000
  165. }]
  166. });
  167. chart.on('click', function (param) {
  168. alert('asdf');
  169. });
  170. chart.on('finished', function () {
  171. // console.log('Render finished');
  172. var url = chart.getDataURL();
  173. var snapshotEl = document.getElementById('snapshot');
  174. snapshotEl.src = url;
  175. });
  176. window.onresize = chart.resize;
  177. // next();
  178. function next() {
  179. if (chunkCount++ < chunkMax) {
  180. var newData = genData1(100000, chunkCount);
  181. chart.appendData({seriesIndex: 0, data: newData});
  182. // console.log('Data loaded');
  183. setTimeout(next, 3000);
  184. }
  185. }
  186. });
  187. });
  188. </script>
  189. </body>
  190. </html>