visualMap-large.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <script src="lib/esl.js"></script>
  7. <script src="lib/config.js"></script>
  8. <script src="lib/jquery.min.js"></script>
  9. <script src="lib/facePrint.js"></script>
  10. <script src="lib/testHelper.js"></script>
  11. <link rel="stylesheet" href="lib/reset.css">
  12. </head>
  13. <body>
  14. <style>
  15. h1 {
  16. line-height: 60px;
  17. height: 60px;
  18. background: #146402;
  19. text-align: center;
  20. font-weight: bold;
  21. color: #eee;
  22. font-size: 14px;
  23. }
  24. .chart {
  25. height: 500px;
  26. }
  27. </style>
  28. <div class="chart" id="main"></div>
  29. <script>
  30. var echarts;
  31. var chart;
  32. var myChart;
  33. var groupCategories = [];
  34. var groupColors = [];
  35. require([
  36. 'echarts'
  37. // 'echarts/chart/map',
  38. // 'echarts/chart/custom',
  39. // 'echarts/component/geo',
  40. // 'echarts/component/legend',
  41. // 'echarts/component/tooltip',
  42. // 'echarts/component/toolbox',
  43. // 'echarts/component/visualMap',
  44. // 'echarts/component/dataZoom'
  45. ], function (ec) {
  46. echarts = ec;
  47. $.get('../map/json/world.json', function (worldJson) {
  48. echarts.registerMap('world', worldJson);
  49. $.getJSON('./data/global-wind.json', function (windData) {
  50. var p = 0;
  51. var maxMag = 0;
  52. var minMag = Infinity;
  53. var data = [];
  54. for (var j = 0; j < windData.ny; j++) {
  55. for (var i = 0; i < windData.nx; i++, p++) {
  56. var vx = windData.data[p][0];
  57. var vy = windData.data[p][1];
  58. var mag = Math.sqrt(vx * vx + vy * vy);
  59. // 数据是一个一维数组
  60. // [ [经度, 维度,向量经度方向的值,向量维度方向的值] ]
  61. data.push([
  62. i / windData.nx * 360 - 180,
  63. j / windData.ny * 180 - 90,
  64. vx,
  65. vy,
  66. mag
  67. ]);
  68. maxMag = Math.max(mag, maxMag);
  69. minMag = Math.min(mag, minMag);
  70. }
  71. }
  72. data.reverse();
  73. var option = {
  74. backgroundColor: '#333',
  75. visualMap: {
  76. left: 'center',
  77. min: minMag,
  78. max: maxMag,
  79. dimension: 4,
  80. inRange: {
  81. // color: ['green', 'yellow', 'red']
  82. color: ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
  83. },
  84. realtime: false,
  85. hoverLink: true,
  86. calculable: true,
  87. textStyle: {
  88. color: '#fff'
  89. },
  90. orient: 'horizontal'
  91. },
  92. geo: {
  93. map: 'world',
  94. left: 0,
  95. right: 0,
  96. top: 0,
  97. zoom: 1,
  98. silent: true,
  99. itemStyle: {
  100. normal: {
  101. areaColor: '#323c48',
  102. borderColor: '#111'
  103. }
  104. }
  105. },
  106. series: {
  107. type: 'custom',
  108. coordinateSystem: 'geo',
  109. data: data,
  110. // silent: true,
  111. encode: {
  112. x: 0,
  113. y: 0
  114. },
  115. renderItem: function (params, api) {
  116. var x = api.value(0), y = api.value(1), dx = api.value(2), dy = api.value(3);
  117. var start = api.coord([Math.max(x - dx / 5, -180), Math.max(y - dy / 5, -90)]);
  118. var end = api.coord([Math.min(x + dx / 5, 180), Math.min(y + dy / 5, 90)]);
  119. return {
  120. type: 'line',
  121. shape: {
  122. x1: start[0], y1: start[1],
  123. x2: end[0], y2: end[1]
  124. },
  125. style: {
  126. lineWidth: 0.5,
  127. stroke: api.visual('color')
  128. }
  129. }
  130. },
  131. progressive: 2000
  132. }
  133. };
  134. testHelper.createChart(echarts, 'main', option);
  135. });
  136. });
  137. });
  138. </script>
  139. </body>
  140. </html>