lazyUpdate.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="lib/esl.js"></script>
  5. <script src="lib/config.js"></script>
  6. <link rel="stylesheet" href="lib/reset.css">
  7. </head>
  8. <body>
  9. <style>
  10. </style>
  11. <div id="main"></div>
  12. <script>
  13. // Schema:
  14. // date,AQIindex,PM2.5,PM10,CO,NO2,SO2
  15. var schema = [
  16. {name: 'date', index: 0, text: '日期'},
  17. {name: 'AQIindex', index: 1, text: 'AQI指数'},
  18. {name: 'PM25', index: 2, text: 'PM2.5'},
  19. {name: 'PM10', index: 3, text: 'PM10'},
  20. {name: 'CO', index: 4, text: '一氧化碳 (CO)'},
  21. {name: 'NO2', index: 5, text: '二氧化氮 (NO2)'},
  22. {name: 'SO2', index: 6, text: '二氧化硫 (SO2)'}
  23. ];
  24. require([
  25. 'data/aqi/BJdata',
  26. 'data/aqi/GZdata',
  27. 'data/aqi/SHdata',
  28. 'echarts'
  29. // 'echarts/chart/scatter',
  30. // 'echarts/component/tooltip'
  31. ], function (dataBJ, dataGZ, dataSH, echarts) {
  32. var chart = echarts.init(document.getElementById('main'));
  33. var dimSize = 6;
  34. var nameList = ['北京', '广州', '上海'];
  35. var color = ['#5793f3', '#d14a61', '#fd9c35'];
  36. function update(isLazy) {
  37. var idx = 0;
  38. var axisPointerLinkList = [];
  39. var axisPointerLinkMap = {};
  40. for (var i = 1; i < dimSize; i++) {
  41. for (var j = 1; j < dimSize; j++) {
  42. var id = i + '-' + j;
  43. var linkItem = axisPointerLinkMap['x' + i];
  44. if (!linkItem) {
  45. linkItem = axisPointerLinkMap['x' + i] = {xAxisId: []};
  46. axisPointerLinkList.push(linkItem);
  47. }
  48. linkItem.xAxisId.push(id);
  49. var linkItem = axisPointerLinkMap['y' + j];
  50. if (!linkItem) {
  51. linkItem = axisPointerLinkMap['y' + j] = {yAxisId: []};
  52. axisPointerLinkList.push(linkItem);
  53. }
  54. linkItem.yAxisId.push(id);
  55. chart.setOption({
  56. tooltip: {
  57. trigger: 'none'
  58. },
  59. axisPointer: {
  60. show: true,
  61. snap: true,
  62. lineStyle: {
  63. type: 'dashed'
  64. },
  65. link: axisPointerLinkList
  66. },
  67. grid: [{
  68. id: id,
  69. left: ((i - 1) / dimSize * 100 + 7) + '%',
  70. top: ((j - 1) / dimSize * 100 + 7) + '%',
  71. width: '15%',
  72. height: '15%'
  73. }],
  74. xAxis: [{
  75. id: id,
  76. gridId: id,
  77. // gridIndex: idx,
  78. axisLabel: {
  79. show: j === dimSize - 1
  80. },
  81. axisTick: {
  82. show: j === dimSize - 1
  83. },
  84. name: j === dimSize - 1 ? schema[i].text : '',
  85. nameLocation: 'middle',
  86. nameGap: 30,
  87. splitNumber: 3
  88. }],
  89. yAxis: [{
  90. id: id,
  91. gridId: id,
  92. // gridIndex: idx,
  93. axisLabel: {
  94. show: i === 1
  95. },
  96. axisTick: {
  97. show: i === 1
  98. },
  99. name: i === 1 ? schema[j].text : '',
  100. nameLocation: 'middle',
  101. nameGap: 30,
  102. splitNumber: 4
  103. }],
  104. series: [dataBJ, dataGZ, dataSH].map(function (data, dataIdx) {
  105. return {
  106. id: id + '-' + dataIdx,
  107. hoverAnimation: false,
  108. name: nameList[dataIdx],
  109. type: 'scatter',
  110. xAxisId: id,
  111. yAxisId: id,
  112. // xAxisIndex: idx,
  113. // yAxisIndex: idx,
  114. data: data.map(function (item) {
  115. return [item[i], item[j]];
  116. }),
  117. itemStyle: {
  118. normal: {
  119. color: color[dataIdx]
  120. }
  121. }
  122. };
  123. })
  124. }, false, isLazy);
  125. idx++;
  126. }
  127. }
  128. }
  129. // console.time('update immediate');
  130. // update(false);
  131. // console.timeEnd('update immediate');
  132. // chart.clear();
  133. setTimeout(function () {
  134. console.time('update lazy');
  135. update(true);
  136. console.timeEnd('update lazy');
  137. }, 1000);
  138. });
  139. </script>
  140. </body>
  141. </html>