parallel-aqi.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. }
  13. #main {
  14. width: 766px;
  15. height: 688px;
  16. }
  17. </style>
  18. <div id="main"></div>
  19. <script>
  20. // Schema:
  21. // date,AQIindex,PM2.5,PM10,CO,NO2,SO2
  22. var schema = [
  23. {name: 'date', index: 0, text: '日期'},
  24. {name: 'AQIindex', index: 1, text: 'AQI指数'},
  25. {name: 'PM25', index: 2, text: 'PM2.5'},
  26. {name: 'PM10', index: 3, text: 'PM10'},
  27. {name: 'CO', index: 4, text: '一氧化碳 (CO)'},
  28. {name: 'NO2', index: 5, text: '二氧化氮 (NO2)'},
  29. {name: 'SO2', index: 6, text: '二氧化硫 (SO2)'},
  30. {name: '等级', index: 7, text: '等级'}
  31. ];
  32. require([
  33. 'data/aqi/BJdata',
  34. 'data/aqi/GZdata',
  35. 'data/aqi/SHdata',
  36. 'zrender/core/util',
  37. 'echarts',
  38. 'echarts/chart/parallel',
  39. 'echarts/component/legend',
  40. 'echarts/component/tooltip',
  41. 'echarts/component/visualMap',
  42. 'echarts/component/parallel',
  43. ], function (dataBJ, dataGZ, dataSH, zrUtil, echarts) {
  44. var chart = echarts.init(document.getElementById('main'));
  45. var lineStyle = {
  46. normal: {
  47. width: 1
  48. // opacity: 0.5,
  49. // shadowBlur: 10,
  50. // shadowOffsetX: 0,
  51. // shadowOffsetY: 0,
  52. // shadowColor: 'rgba(0, 0, 0, 0.5)'
  53. }
  54. };
  55. chart.setOption({
  56. animation: true,
  57. legend: {
  58. bottom: 30,
  59. data: ['北京', '上海', '广州'],
  60. itemGap: 20,
  61. textStyle: {
  62. // color: '#fff',
  63. fontSize: 16
  64. }
  65. },
  66. tooltip: {
  67. padding: 10,
  68. backgroundColor: '#222',
  69. borderColor: '#777',
  70. borderWidth: 1,
  71. formatter: function (obj) {
  72. var value = obj[0].value;
  73. return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">'
  74. + obj[0].seriesName + ' ' + value[0] + '日期:'
  75. + value[7]
  76. + '</div>'
  77. + schema[1].text + ':' + value[1] + '<br>'
  78. + schema[2].text + ':' + value[2] + '<br>'
  79. + schema[3].text + ':' + value[3] + '<br>'
  80. + schema[4].text + ':' + value[4] + '<br>'
  81. + schema[5].text + ':' + value[5] + '<br>'
  82. + schema[6].text + ':' + value[6] + '<br>';
  83. }
  84. },
  85. visualMap: {
  86. show: true,
  87. min: 0,
  88. max: 150,
  89. dimension: 2,
  90. inRange: {
  91. color: ['#d94e5d','#eac736','#50a3ba'].reverse()
  92. },
  93. outOfRange: {
  94. color: ['#ccc'],
  95. opacity: 0.001
  96. }
  97. },
  98. // dataZoom: {
  99. // show: true,
  100. // orient: 'vertical',
  101. // parallelAxisIndex: [0]
  102. // },
  103. parallelAxis: [
  104. {dim: 0, name: schema[0].text, inverse: true, max: 31, nameLocation: 'end'},
  105. {dim: 1, name: schema[1].text},
  106. {dim: 2, name: schema[2].text},
  107. {dim: 3, name: schema[3].text},
  108. {dim: 4, name: schema[4].text},
  109. {dim: 5, name: schema[5].text},
  110. {dim: 6, name: schema[6].text},
  111. {dim: 7, name: schema[7].text,
  112. type: 'category', data: ['优', '良', '轻度污染', '中度污染', '重度污染', '严重污染']}
  113. ],
  114. parallel: {
  115. bottom: 100,
  116. parallelAxisDefault: {
  117. type: 'value',
  118. name: 'AQI指数',
  119. nameLocation: 'end',
  120. nameGap: 20,
  121. tooltip: {
  122. show: true
  123. },
  124. nameTextStyle: {
  125. // color: '#fff',
  126. fontSize: 14
  127. },
  128. axisLine: {
  129. lineStyle: {
  130. // color: '#aaa'
  131. }
  132. },
  133. axisTick: {
  134. lineStyle: {
  135. // color: '#777'
  136. }
  137. },
  138. splitLine: {
  139. show: false
  140. },
  141. axisLabel: {
  142. textStyle: {
  143. // color: '#fff'
  144. }
  145. }
  146. }
  147. },
  148. series: [
  149. {
  150. name: '北京',
  151. type: 'parallel',
  152. lineStyle: lineStyle,
  153. data: dataBJ
  154. // data: [
  155. // [ 1, 32,12 , 19, 28,1.39,24, 8,"优"],
  156. // ]
  157. },
  158. {
  159. name: '上海',
  160. type: 'parallel',
  161. lineStyle: lineStyle,
  162. data: dataSH
  163. // data: [
  164. // [ 1, 332,212 , 119, 128,12.39,124, 18,"良"],
  165. // ]
  166. },
  167. {
  168. name: '广州',
  169. type: 'parallel',
  170. lineStyle: lineStyle,
  171. data: dataGZ
  172. }
  173. ]
  174. });
  175. chart.on('axisAreaSelected', function (event) {
  176. var indices = chart.getModel().getSeries()[0].getRawIndicesByActiveState('active');
  177. console.log('北京: ', indices);
  178. });
  179. });
  180. </script>
  181. </body>
  182. </html>