parallel-aqi.html 7.1 KB

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