regression_logarithmic.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <!DOCTYPE html>
  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. </head>
  10. <body>
  11. <style>
  12. html, body, #main {
  13. width: 100%;
  14. height: 100%;
  15. margin: 0;
  16. padding: 0;
  17. }
  18. </style>
  19. <div id="main"></div>
  20. <script>
  21. require([
  22. 'echarts',
  23. 'ecStat'
  24. ], function (echarts, ecStat) {
  25. var chart = echarts.init(document.getElementById('main'));
  26. var data0 = [
  27. [28604,77,17096869,'Australia',1990],
  28. [31163,77.4,27662440,'Canada',1990],
  29. [1516,68,1154605773,'China',1990],
  30. [13670,74.7,10582082,'Cuba',1990],
  31. [28599,75,4986705,'Finland',1990],
  32. [29476,77.1,56943299,'France',1990],
  33. [31476,75.4,78958237,'Germany',1990],
  34. [28666,78.1,254830,'Iceland',1990],
  35. [1777,57.7,870601776,'India',1990],
  36. [29550,79.1,122249285,'Japan',1990],
  37. [2076,67.9,20194354,'North Korea',1990],
  38. [12087,72,42972254,'South Korea',1990],
  39. [24021,75.4,3397534,'New Zealand',1990],
  40. [43296,76.8,4240375,'Norway',1990],
  41. [10088,70.8,38195258,'Poland',1990],
  42. [19349,69.6,147568552,'Russia',1990],
  43. [10670,67.3,53994605,'Turkey',1990],
  44. [26424,75.7,57110117,'United Kingdom',1990],
  45. [37062,75.4,252847810,'United States',1990]
  46. ];
  47. var data1 = [
  48. [44056,81.8,23968973,'Australia',2015],
  49. [43294,81.7,35939927,'Canada',2015],
  50. [13334,76.9,1376048943,'China',2015],
  51. [21291,78.5,11389562,'Cuba',2015],
  52. [38923,80.8,5503457,'Finland',2015],
  53. [37599,81.9,64395345,'France',2015],
  54. [44053,81.1,80688545,'Germany',2015],
  55. [42182,82.8,329425,'Iceland',2015],
  56. [5903,66.8,1311050527,'India',2015],
  57. [36162,83.5,126573481,'Japan',2015],
  58. [1390,71.4,25155317,'North Korea',2015],
  59. [34644,80.7,50293439,'South Korea',2015],
  60. [34186,80.6,4528526,'New Zealand',2015],
  61. [64304,81.6,5210967,'Norway',2015],
  62. [24787,77.3,38611794,'Poland',2015],
  63. [23038,73.13,143456918,'Russia',2015],
  64. [19360,76.5,78665830,'Turkey',2015],
  65. [38225,81.4,64715810,'United Kingdom',2015],
  66. [53354,79.1,321773631,'United States',2015]
  67. ];
  68. var data = [
  69. [28604,77],
  70. [31163,77.4],
  71. [1516,68],
  72. [13670,74.7],
  73. [28599,75],
  74. [29476,77.1],
  75. [31476,75.4],
  76. [28666,78.1],
  77. [1777,57.7],
  78. [29550,79.1],
  79. [2076,67.9],
  80. [12087,72],
  81. [24021,75.4],
  82. [43296,76.8],
  83. [10088,70.8],
  84. [19349,69.6],
  85. [10670,67.3],
  86. [26424,75.7],
  87. [37062,75.4],
  88. [44056,81.8],
  89. [43294,81.7],
  90. [13334,76.9],
  91. [21291,78.5],
  92. [38923,80.8],
  93. [37599,81.9],
  94. [44053,81.1],
  95. [42182,82.8],
  96. [5903,66.8],
  97. [36162,83.5],
  98. [1390,71.4],
  99. [34644,80.7],
  100. [34186,80.6],
  101. [64304,81.6],
  102. [24787,77.3],
  103. [23038,73.13],
  104. [19360,76.5],
  105. [38225,81.4],
  106. [53354,79.1]
  107. ];
  108. var myRegression = ecStat.regression('logarithmic', data);
  109. chart.setOption({
  110. legend: {
  111. data: ['1990', '2015']
  112. },
  113. title: {
  114. text: '1990 与 2015年各国人均寿命与GDP'
  115. },
  116. tooltip: {
  117. trigger: 'axis',
  118. axisPointer: {
  119. type: 'cross'
  120. }
  121. },
  122. xAxis: {
  123. type: 'value',
  124. splitLine: {
  125. lineStyle: {
  126. type: 'dashed'
  127. }
  128. },
  129. },
  130. yAxis: {
  131. type: 'value',
  132. splitLine: {
  133. lineStyle: {
  134. type: 'dashed'
  135. }
  136. },
  137. },
  138. series: [{
  139. name: '1990',
  140. type: 'scatter',
  141. symbolSize: function (data) {
  142. return Math.sqrt(data[2]) / 5e2;
  143. },
  144. label: {
  145. emphasis: {
  146. show: true,
  147. formatter: function (param) {
  148. return param.data[3];
  149. },
  150. position: 'top'
  151. }
  152. },
  153. itemStyle: {
  154. normal: {
  155. shadowBlur: 10,
  156. shadowColor: 'rgba(120, 36, 50, 0.5)',
  157. shadowOffsetY: 5,
  158. color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{
  159. offset: 0,
  160. color: 'rgb(251, 118, 123)'
  161. }, {
  162. offset: 1,
  163. color: 'rgb(204, 46, 72)'
  164. }])
  165. }
  166. },
  167. data: data0
  168. },{
  169. name: '2015',
  170. type: 'scatter',
  171. symbolSize: function (data) {
  172. return Math.sqrt(data[2]) / 5e2;
  173. },
  174. label: {
  175. emphasis: {
  176. show: true,
  177. formatter: function (param) {
  178. return param.data[3];
  179. },
  180. position: 'top'
  181. }
  182. },
  183. itemStyle: {
  184. normal: {
  185. shadowBlur: 10,
  186. shadowColor: 'rgba(25, 100, 150, 0.5)',
  187. shadowOffsetY: 5,
  188. color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{
  189. offset: 0,
  190. color: 'rgb(129, 227, 238)'
  191. }, {
  192. offset: 1,
  193. color: 'rgb(25, 183, 207)'
  194. }])
  195. }
  196. },
  197. data: data1
  198. },{
  199. name: 'line',
  200. type: 'line',
  201. lineStyle: {
  202. normal: {
  203. color: '#2f4554'
  204. }
  205. },
  206. smooth: true,
  207. showSymbol: false,
  208. data: myRegression.points,
  209. markPoint: {
  210. itemStyle: {
  211. normal: {
  212. color: 'transparent'
  213. }
  214. },
  215. label: {
  216. normal: {
  217. show: true,
  218. formatter: myRegression.expression,
  219. textStyle: {
  220. color: '#333',
  221. fontSize: 14
  222. }
  223. }
  224. },
  225. data: [{
  226. coord: myRegression.points[myRegression.points.length - 1]
  227. }]
  228. }
  229. }]
  230. });
  231. });
  232. </script>
  233. </body>
  234. </html>