echartsBar.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_GraphBar"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. </head>
  11. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  13. <script type="text/javascript" include="echarts" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, resultLayer,
  17. url = host + "/iserver/services/map-world/rest/maps/世界地图_Gray";
  18. var url2 = host + "/iserver/services/map-china400/rest/maps/China";
  19. map = L.map('map', {
  20. preferCanvas: true,
  21. crs: L.CRS.EPSG4326,
  22. center: [30.236064370321, 120.14322240845],
  23. maxZoom: 18,
  24. zoom: 5
  25. });
  26. L.supermap.tiledMapLayer(url).addTo(map);
  27. option = {
  28. legend: {
  29. data: [resources.text_rainfall, resources.text_runoff],
  30. align: 'left'
  31. },
  32. toolbox: {
  33. feature: {
  34. magicType: {
  35. type: ['stack', 'tiled']
  36. },
  37. saveAsImage: {
  38. pixelRatio: 2
  39. }
  40. }
  41. },
  42. tooltip: {},
  43. xAxis: {
  44. data: [resources.text_monday,resources.text_tuesday,resources.text_wednesday,resources.text_thursday,resources.text_friday,resources.text_saturday,resources.text_sunday],
  45. silent: false,
  46. splitLine: {
  47. show: false
  48. }
  49. },
  50. yAxis: {},
  51. series: [{
  52. name: 'bar',
  53. type: 'bar',
  54. animationDelay: function (idx) {
  55. return idx * 10;
  56. }
  57. }, {
  58. name: 'bar2',
  59. type: 'bar',
  60. animationDelay: function (idx) {
  61. return idx * 10 + 100;
  62. }
  63. }],
  64. animationEasing: 'elasticOut',
  65. animationDelayUpdate: function (idx) {
  66. return idx * 5;
  67. }
  68. };
  69. var div = L.DomUtil.create('div');
  70. var chart = echarts.init(div, '', {
  71. width: 500,
  72. height: 300
  73. });
  74. chart.setOption(option);
  75. query();
  76. function query() {
  77. clearLayer();
  78. var param = new SuperMap.QueryBySQLParameters({
  79. queryParams: [{
  80. name: "China_ProCenCity_pt@China",
  81. attributeFilter: "1 = 1"
  82. }, {
  83. name: "China_Capital_pt@China",
  84. attributeFilter: "1 = 1"
  85. }]
  86. });
  87. L.supermap
  88. .queryService(url2)
  89. .queryBySQL(param, function (serviceResult) {
  90. serviceResult.result.recordsets.map(function (records) {
  91. resultLayer = L.geoJSON(records.features, {
  92. coordsToLatLng: function (coords) {
  93. var latlng = L.CRS.EPSG3857.unproject(L.point(coords[0], coords[1]));
  94. latlng.alt = coords[2];
  95. return latlng;
  96. }
  97. }).bindPopup(function (layer) {
  98. var city = layer.feature.properties.NAME;
  99. var data1 = [];
  100. var data2 = [];
  101. for (var i = 0; i < 7; i++) {
  102. var data = Math.random().toFixed(2);
  103. data1.push(data);
  104. data2.push(data * (Math.random() + 1.5));
  105. }
  106. chart.setOption({
  107. title: {
  108. text: city,
  109. subtext: resources.text_fictitiouData,
  110. },
  111. series: [
  112. {
  113. name: resources.text_rainfall,
  114. data: data1
  115. },
  116. {
  117. name:resources.text_runoff,
  118. data: data2
  119. }
  120. ]
  121. });
  122. return chart.getDom();
  123. }, {maxWidth: 600}).addTo(map);
  124. });
  125. });
  126. }
  127. function clearLayer() {
  128. if (resultLayer) {
  129. resultLayer.removeFrom(map);
  130. resultLayer.removeFrom(map);
  131. }
  132. }
  133. </script>
  134. </body>
  135. </html>