connect2.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. body {
  11. background: #000;
  12. width: 100%;
  13. height: 100%;
  14. margin: 0;
  15. }
  16. #chart1, #chart2 {
  17. width: 50%;
  18. height: 100%;
  19. float: left;
  20. }
  21. </style>
  22. <div id="main">
  23. <div id="chart1"></div>
  24. <div id="chart2"></div>
  25. </div>
  26. <script>
  27. // Schema:
  28. // date,AQIindex,PM2.5,PM10,CO,NO2,SO2
  29. var schema = [
  30. {name: 'date', index: 0, text: '日'},
  31. {name: 'AQIindex', index: 1, text: 'AQI指数'},
  32. {name: 'PM25', index: 2, text: 'PM2.5'},
  33. {name: 'PM10', index: 3, text: 'PM10'},
  34. {name: 'CO', index: 4, text: '一氧化碳(CO)'},
  35. {name: 'NO2', index: 5, text: '二氧化氮(NO2)'},
  36. {name: 'SO2', index: 6, text: '二氧化硫(SO2)'}
  37. ];
  38. require([
  39. 'data/aqi/BJdata',
  40. 'data/aqi/GZdata',
  41. 'data/aqi/SHdata',
  42. 'echarts',
  43. 'echarts/chart/scatter',
  44. 'echarts/component/legend',
  45. 'echarts/component/tooltip',
  46. 'echarts/component/grid',
  47. 'echarts/component/visualMapContinuous'
  48. ], function (dataBJ, dataGZ, dataSH, echarts) {
  49. var chart1 = echarts.init(document.getElementById('chart1'));
  50. var chart2 = echarts.init(document.getElementById('chart2'));
  51. var option1 = makeChartOption();
  52. var option2 = makeChartOption();
  53. option1.visualMap.inRange = {
  54. symbolSize: [10, 70]
  55. };
  56. option1.visualMap.outOfRange = {
  57. symbolSize: [10, 70],
  58. color: ['rgba(255,255,255,.2)']
  59. };
  60. option1.visualMap.dimension = 'z';
  61. option1.visualMap.max = 250;
  62. option2.visualMap.inRange = {
  63. colorLightness: [1, 0.5]
  64. };
  65. option2.visualMap.outOfRange = {
  66. color: ['rgba(255,255,255,.2)']
  67. };
  68. option2.visualMap.dimension = 'z';
  69. option2.visualMap.max = 250;
  70. chart1.setOption(option1);
  71. chart2.setOption(option2);
  72. echarts.connect([chart1, chart2]);
  73. function makeChartOption(legend) {
  74. var itemStyle = {
  75. normal: {
  76. opacity: 0.8,
  77. shadowBlur: 10,
  78. shadowOffsetX: 0,
  79. shadowOffsetY: 0,
  80. shadowColor: 'rgba(0, 0, 0, 0.5)'
  81. }
  82. };
  83. return {
  84. color: [
  85. '#dd4444', '#fec42c', '#80F1BE'
  86. ],
  87. legend: {
  88. top: 'top',
  89. data: ['北京', '上海', '广州'],
  90. textStyle: {
  91. color: '#fff',
  92. fontSize: 20
  93. }
  94. },
  95. grid: {
  96. left: '10%',
  97. right: 200,
  98. top: '15%',
  99. bottom: '10%'
  100. },
  101. tooltip: {
  102. padding: 10,
  103. backgroundColor: '#222',
  104. borderColor: '#777',
  105. borderWidth: 1,
  106. formatter: function (obj) {
  107. var value = obj.value;
  108. return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">'
  109. + obj.seriesName + ' ' + value[0] + '日:'
  110. + value[7]
  111. + '</div>'
  112. + schema[1].text + ':' + value[1] + '<br>'
  113. + schema[2].text + ':' + value[2] + '<br>'
  114. + schema[3].text + ':' + value[3] + '<br>'
  115. + schema[4].text + ':' + value[4] + '<br>'
  116. + schema[5].text + ':' + value[5] + '<br>'
  117. + schema[6].text + ':' + value[6] + '<br>';
  118. }
  119. },
  120. xAxis: {
  121. type: 'value',
  122. name: '日期',
  123. nameGap: 16,
  124. nameTextStyle: {
  125. color: '#fff',
  126. fontSize: 14
  127. },
  128. max: 31,
  129. splitLine: {
  130. show: false
  131. },
  132. axisTick: {
  133. lineStyle: {
  134. color: '#777'
  135. }
  136. },
  137. axisLabel: {
  138. formatter: '{value}',
  139. textStyle: {
  140. color: '#fff'
  141. }
  142. }
  143. },
  144. yAxis: {
  145. type: 'value',
  146. name: 'AQI指数',
  147. nameLocation: 'end',
  148. nameGap: 20,
  149. nameTextStyle: {
  150. color: '#fff',
  151. fontSize: 20
  152. },
  153. axisTick: {
  154. lineStyle: {
  155. color: '#777'
  156. }
  157. },
  158. splitLine: {
  159. show: false
  160. },
  161. axisLabel: {
  162. textStyle: {
  163. color: '#fff'
  164. }
  165. }
  166. },
  167. visualMap: {
  168. left: 'right',
  169. top: 'top',
  170. min: 0,
  171. itemWidth: 30,
  172. itemHeight: 130,
  173. calculable: true,
  174. precision: 0.1,
  175. text: ['圆形大小:PM2.5'],
  176. textGap: 30,
  177. textStyle: {
  178. color: '#fff'
  179. },
  180. inRange: {
  181. symbolSize: [10, 70]
  182. },
  183. outOfRange: {
  184. symbolSize: [10, 70],
  185. color: ['rgba(255,255,255,.2)']
  186. },
  187. controller: {
  188. outOfRange: {
  189. color: ['#444']
  190. }
  191. }
  192. },
  193. series: [
  194. {
  195. name: '北京',
  196. type: 'scatter',
  197. itemStyle: itemStyle,
  198. symbolSize: 20,
  199. data: dataBJ
  200. },
  201. {
  202. name: '上海',
  203. type: 'scatter',
  204. itemStyle: itemStyle,
  205. symbolSize: 20,
  206. data: dataSH
  207. },
  208. {
  209. name: '广州',
  210. type: 'scatter',
  211. itemStyle: itemStyle,
  212. symbolSize: 20,
  213. data: dataGZ
  214. }
  215. ]
  216. };
  217. }
  218. });
  219. </script>
  220. </body>
  221. </html>