echartsPie.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_GraphPie"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. <script type="text/javascript" include="echarts" src="../../dist/ol/include-ol.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  13. <div id="map" class='map' style="margin:0 auto;width: 100%;height: 100%;"></div>
  14. <div id="popup"></div>
  15. <script type="text/javascript">
  16. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  17. var resultLayer;
  18. var map = new ol.Map({
  19. target: 'map',
  20. controls: ol.control.defaults({
  21. attributionOptions: {
  22. collapsed: false
  23. }
  24. })
  25. .extend([new ol.supermap.control.Logo()]),
  26. view: new ol.View({
  27. center: [105.2, 31.6],
  28. zoom: 5,
  29. projection: 'EPSG:4326',
  30. multiWorld: true
  31. }),
  32. layers: [new ol.layer.Tile({
  33. source: new ol.source.TileSuperMapRest({
  34. url: host + "/iserver/services/map-world/rest/maps/世界地图_Gray",
  35. }),
  36. projection: 'EPSG:4326'
  37. })]
  38. });
  39. var popup = new ol.Overlay({
  40. element: document.getElementById('popup'),
  41. offset: [5, 5]
  42. });
  43. map.addOverlay(popup);
  44. var categoryDataMap = {
  45. "北京市": [{
  46. value: 335,
  47. name: resources.text_class + 'A'
  48. },
  49. {
  50. value: 679,
  51. name: resources.text_class + 'B'
  52. },
  53. {
  54. value: 1299,
  55. name: resources.text_class + 'C'
  56. }
  57. ],
  58. "广州市": [{
  59. value: 117,
  60. name: resources.text_class + 'A'
  61. },
  62. {
  63. value: 1267,
  64. name: resources.text_class + 'B'
  65. },
  66. {
  67. value: 1048,
  68. name: resources.text_class + 'C'
  69. }
  70. ],
  71. "上海市": [{
  72. value: 475,
  73. name: resources.text_class + 'A'
  74. },
  75. {
  76. value: 1450,
  77. name: resources.text_class + 'B'
  78. },
  79. {
  80. value: 875,
  81. name: resources.text_class + 'C'
  82. }
  83. ]
  84. }
  85. var dataMap = {
  86. "北京市": [{
  87. value: 335,
  88. name: resources.text_commodity + 'A'
  89. },
  90. {
  91. value: 310,
  92. name: resources.text_commodity + 'B'
  93. },
  94. {
  95. value: 234,
  96. name: resources.text_commodity + 'C'
  97. },
  98. {
  99. value: 135,
  100. name: resources.text_commodity + 'D'
  101. },
  102. {
  103. value: 1048,
  104. name: resources.text_commodity + 'E'
  105. },
  106. {
  107. value: 251,
  108. name: resources.text_commodity + 'F'
  109. }
  110. ],
  111. "广州市": [{
  112. value: 117,
  113. name: resources.text_commodity + 'A'
  114. },
  115. {
  116. value: 284,
  117. name: resources.text_commodity + 'B'
  118. },
  119. {
  120. value: 768,
  121. name: resources.text_commodity + 'C'
  122. },
  123. {
  124. value: 215,
  125. name: resources.text_commodity + 'D'
  126. },
  127. {
  128. value: 901,
  129. name: resources.text_commodity + 'E'
  130. },
  131. {
  132. value: 148,
  133. name: resources.text_commodity + 'F'
  134. }
  135. ],
  136. "上海市": [{
  137. value: 475,
  138. name: resources.text_commodity + 'A'
  139. },
  140. {
  141. value: 29,
  142. name: resources.text_commodity + 'B'
  143. },
  144. {
  145. value: 430,
  146. name: resources.text_commodity + 'C'
  147. },
  148. {
  149. value: 981,
  150. name: resources.text_commodity + 'D'
  151. },
  152. {
  153. value: 732,
  154. name: resources.text_commodity + 'E'
  155. },
  156. {
  157. value: 143,
  158. name: resources.text_commodity + 'F'
  159. }
  160. ]
  161. }
  162. var option = {
  163. title: {
  164. text: resources.text_beijingCommoditySales,
  165. subtext: resources.text_fictitiouData,
  166. textStyle: {
  167. color: '#fff',
  168. fontSize: 16
  169. }
  170. },
  171. backgroundColor: '#404a59',
  172. tooltip: {
  173. trigger: 'item',
  174. formatter: "{a} <br/>{b}: {c} ({d}%)"
  175. },
  176. legend: {
  177. orient: 'vertical',
  178. x: 'right',
  179. y: 'bottom',
  180. textStyle: {
  181. color: '#fff',
  182. fontSize: 12
  183. },
  184. data: [resources.text_commodity + 'A', resources.text_commodity + 'B', resources.text_commodity +
  185. 'C', resources.text_commodity + 'D', resources.text_commodity + 'E', resources.text_commodity +
  186. 'F'
  187. ]
  188. },
  189. series: [{
  190. name: resources.text_commodityClass,
  191. type: 'pie',
  192. selectedMode: 'single',
  193. radius: [0, '30%'],
  194. label: {
  195. normal: {
  196. position: 'inner'
  197. }
  198. },
  199. labelLine: {
  200. normal: {
  201. show: false
  202. }
  203. },
  204. data: categoryDataMap['北京市']
  205. },
  206. {
  207. name: resources.text_commodity,
  208. type: 'pie',
  209. radius: ['40%', '55%'],
  210. data: dataMap['北京市']
  211. }
  212. ]
  213. };
  214. var chart = echarts.init(document.createElement('div'), '', {
  215. width: 500,
  216. height: 300
  217. });
  218. chart.setOption(option);
  219. query();
  220. function query() {
  221. clearLayer();
  222. var queryService = new ol.supermap.QueryService(host + "/iserver/services/map-china400/rest/maps/China");
  223. var param = new SuperMap.QueryBySQLParameters({
  224. queryParams: [{
  225. name: "China_ProCenCity_pt@China",
  226. attributeFilter: "NAME = '广州市' or NAME = '上海市'"
  227. }, {
  228. name: "China_Capital_pt@China",
  229. attributeFilter: "NAME = '北京市'"
  230. }]
  231. });
  232. queryService.queryBySQL(param, function (serviceResult) {
  233. var features = [];
  234. for (var i = 0; i < serviceResult.result.recordsets.length; i++) {
  235. var temp = (new ol.format.GeoJSON()).readFeatures(serviceResult.result.recordsets[i].features, {
  236. dataProjection: 'EPSG:3857',
  237. featureProjection: 'EPSG:4326'
  238. });
  239. features = features.concat(temp);
  240. }
  241. resultLayer = new ol.layer.Vector({
  242. source: new ol.source.Vector({
  243. wrapX: false,
  244. features: features
  245. })
  246. });
  247. map.addLayer(resultLayer);
  248. var select = new ol.interaction.Select();
  249. map.addInteraction(select);
  250. select.on('select', function (e) {
  251. if (this.getFeatures().getLength() > 0) {
  252. var city = this.getFeatures().item(0).getProperties().NAME;
  253. var data1 = [];
  254. var data2 = [];
  255. for (var i = 0; i < 7; i++) {
  256. var data = Math.random().toFixed(2);
  257. data1.push(data);
  258. data2.push(data * (Math.random() + 1.5));
  259. }
  260. chart.setOption({
  261. title: {
  262. text: city + resources.text_commoditySales,
  263. },
  264. series: [{
  265. name: resources.text_commodityClass,
  266. data: categoryDataMap[city]
  267. },
  268. {
  269. name: resources.text_commodity,
  270. data: dataMap[city]
  271. }
  272. ]
  273. });
  274. popup.setElement(chart.getDom());
  275. var coordinate = e.mapBrowserEvent.coordinate;
  276. popup.setPosition(coordinate);
  277. } else {
  278. popup.setPosition(undefined);
  279. }
  280. map.getView().setCenter(e.mapBrowserEvent.coordinate);
  281. });
  282. });
  283. }
  284. function clearLayer() {
  285. if (resultLayer) {
  286. map.removeLayer(resultLayer);
  287. }
  288. }
  289. </script>
  290. </body>
  291. </html>