visualMap-categories.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. ];
  27. require([
  28. 'data/aqi/BJdata',
  29. 'data/aqi/GZdata',
  30. 'data/aqi/SHdata',
  31. 'echarts',
  32. 'echarts/chart/scatter',
  33. 'echarts/component/legend',
  34. 'echarts/component/tooltip',
  35. 'echarts/component/grid',
  36. 'echarts/component/visualMapPiecewise'
  37. ], function (dataBJ, dataGZ, dataSH, echarts) {
  38. var chart = echarts.init(document.getElementById('main'), null, {
  39. renderer: 'canvas'
  40. });
  41. var itemStyle = {
  42. normal: {
  43. opacity: 0.8,
  44. shadowBlur: 10,
  45. shadowOffsetX: 0,
  46. shadowOffsetY: 0,
  47. shadowColor: 'rgba(0, 0, 0, 0.5)'
  48. }
  49. };
  50. chart.setOption({
  51. color: [
  52. '#dd4444', '#fec42c', '#80F1BE'
  53. ],
  54. legend: {
  55. y: 'top',
  56. data: ['北京', '上海', '广州'],
  57. textStyle: {
  58. color: '#fff',
  59. fontSize: 20
  60. }
  61. },
  62. grid: {
  63. left: '10%',
  64. right: 200,
  65. top: '15%',
  66. bottom: '10%'
  67. },
  68. tooltip: {
  69. padding: 10,
  70. backgroundColor: '#222',
  71. borderColor: '#777',
  72. borderWidth: 1,
  73. formatter: function (obj) {
  74. var value = obj.value;
  75. return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">'
  76. + obj.seriesName + ' ' + value[0] + '日:'
  77. + value[7]
  78. + '</div>'
  79. + schema[1].text + ':' + value[1] + '<br>'
  80. + schema[2].text + ':' + value[2] + '<br>'
  81. + schema[3].text + ':' + value[3] + '<br>'
  82. + schema[4].text + ':' + value[4] + '<br>'
  83. + schema[5].text + ':' + value[5] + '<br>'
  84. + schema[6].text + ':' + value[6] + '<br>';
  85. }
  86. },
  87. xAxis: {
  88. type: 'value',
  89. name: '日期',
  90. nameGap: 16,
  91. nameTextStyle: {
  92. color: '#fff',
  93. fontSize: 14
  94. },
  95. max: 31,
  96. splitLine: {
  97. show: false
  98. },
  99. axisTick: {
  100. lineStyle: {
  101. color: '#777'
  102. }
  103. },
  104. axisLabel: {
  105. formatter: '{value}',
  106. textStyle: {
  107. color: '#fff'
  108. }
  109. },
  110. },
  111. yAxis: {
  112. type: 'value',
  113. name: 'AQI指数',
  114. nameLocation: 'end',
  115. nameGap: 20,
  116. nameTextStyle: {
  117. color: '#fff',
  118. fontSize: 20
  119. },
  120. axisTick: {
  121. lineStyle: {
  122. color: '#777'
  123. }
  124. },
  125. splitLine: {
  126. show: false
  127. },
  128. axisLabel: {
  129. textStyle: {
  130. color: '#fff'
  131. }
  132. }
  133. },
  134. visualMap: [
  135. {
  136. left: null,
  137. right: 0,
  138. dimension: 7,
  139. selected: {
  140. '轻度污染': false,
  141. '良': false
  142. },
  143. categories: ['严重污染', '重度污染', '中度污染', '轻度污染', '良', '优'],
  144. calculable: true,
  145. precision: 0.1,
  146. inRange: {
  147. symbolSize: 30,
  148. symbol: {
  149. '优': 'diamond',
  150. '': 'circle'
  151. }
  152. },
  153. outOfRange: {
  154. color: '#777',
  155. symbolSize: {
  156. '优': 50,
  157. '': 30
  158. },
  159. symbol: {
  160. '优': 'diamond',
  161. '': 'circle'
  162. }
  163. },
  164. textStyle: {
  165. color: '#fff'
  166. }
  167. }
  168. ],
  169. series: [
  170. {
  171. name: '北京',
  172. type: 'scatter',
  173. itemStyle: itemStyle,
  174. data: dataBJ
  175. },
  176. {
  177. name: '上海',
  178. type: 'scatter',
  179. itemStyle: itemStyle,
  180. data: dataSH
  181. },
  182. {
  183. name: '广州',
  184. type: 'scatter',
  185. itemStyle: itemStyle,
  186. data: dataGZ
  187. }
  188. ]
  189. });
  190. })
  191. </script>
  192. </body>
  193. </html>