scatter-random-stream-fix-axis.html 8.0 KB

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