lazyUpdate.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <link rel="stylesheet" href="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. ], function (dataBJ, dataGZ, dataSH, echarts) {
  31. var chart = echarts.init(document.getElementById('main'));
  32. var dimSize = 6;
  33. var nameList = ['北京', '广州', '上海'];
  34. var color = ['#5793f3', '#d14a61', '#fd9c35'];
  35. function update(isLazy) {
  36. var idx = 0;
  37. for (var i = 1; i < dimSize; i++) {
  38. for (var j = 1; j < dimSize; j++) {
  39. var id = i + '-' + j;
  40. chart.setOption({
  41. grid: [{
  42. id: id,
  43. left: ((i - 1) / dimSize * 100 + 7) + '%',
  44. top: ((j - 1) / dimSize * 100 + 7) + '%',
  45. width: '15%',
  46. height: '15%'
  47. }],
  48. xAxis: [{
  49. id: id,
  50. gridId: id,
  51. // gridIndex: idx,
  52. axisLabel: {
  53. show: j === dimSize - 1
  54. },
  55. axisTick: {
  56. show: j === dimSize - 1
  57. },
  58. name: j === dimSize - 1 ? schema[i].text : '',
  59. nameLocation: 'middle',
  60. nameGap: 30,
  61. splitNumber: 3
  62. }],
  63. yAxis: [{
  64. id: id,
  65. gridId: id,
  66. // gridIndex: idx,
  67. axisLabel: {
  68. show: i === 1
  69. },
  70. axisTick: {
  71. show: i === 1
  72. },
  73. name: i === 1 ? schema[j].text : '',
  74. nameLocation: 'middle',
  75. nameGap: 30,
  76. splitNumber: 4
  77. }],
  78. series: [dataBJ, dataGZ, dataSH].map(function (data, dataIdx) {
  79. return {
  80. id: id + '-' + dataIdx,
  81. hoverAnimation: false,
  82. name: nameList[dataIdx],
  83. type: 'scatter',
  84. xAxisId: id,
  85. yAxisId: id,
  86. // xAxisIndex: idx,
  87. // yAxisIndex: idx,
  88. data: data.map(function (item) {
  89. return [item[i], item[j]];
  90. }),
  91. itemStyle: {
  92. normal: {
  93. color: color[dataIdx]
  94. }
  95. }
  96. };
  97. })
  98. }, false, isLazy);
  99. idx++;
  100. }
  101. }
  102. }
  103. console.time('update immediate');
  104. update(false);
  105. console.timeEnd('update immediate');
  106. chart.clear();
  107. setTimeout(function () {
  108. console.time('update lazy');
  109. update(true);
  110. console.timeEnd('update lazy');
  111. }, 1000);
  112. });
  113. </script>
  114. </body>
  115. </html>