regression_polynomial.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 data = [
  27. [96.24, 11.35],
  28. [33.09, 85.11],
  29. [57.60, 36.61],
  30. [36.77, 27.26],
  31. [20.10, 6.72],
  32. [45.53, 36.37],
  33. [110.07, 80.13],
  34. [72.05, 20.88],
  35. [39.82, 37.15],
  36. [48.05, 70.50],
  37. [0.85, 2.57],
  38. [51.66, 63.70],
  39. [61.07, 127.13],
  40. [64.54, 33.59],
  41. [35.50, 25.01],
  42. [226.55, 664.02],
  43. [188.60, 175.31],
  44. [81.31, 108.68]
  45. ];
  46. var myRegression = ecStat.regression('polynomial', data, 3);
  47. chart.setOption({
  48. tooltip: {
  49. trigger: 'axis',
  50. axisPointer: {
  51. type: 'cross'
  52. }
  53. },
  54. title: {
  55. text: '18 家公司的净利润和主营业务收入(百万元)',
  56. left: 'center',
  57. top: 16
  58. },
  59. xAxis: {
  60. type: 'value',
  61. splitLine: {
  62. lineStyle: {
  63. type: 'dashed'
  64. }
  65. },
  66. splitNumber: 20
  67. },
  68. yAxis: {
  69. type: 'value',
  70. min: -40,
  71. splitLine: {
  72. lineStyle: {
  73. type: 'dashed'
  74. }
  75. }
  76. },
  77. series: [{
  78. name: 'scatter',
  79. type: 'scatter',
  80. label: {
  81. emphasis: {
  82. show: true
  83. }
  84. },
  85. data: data
  86. },{
  87. name: 'line',
  88. type: 'line',
  89. smooth: true,
  90. showSymbol: false,
  91. data: myRegression.points,
  92. markPoint: {
  93. itemStyle: {
  94. normal: {
  95. color: 'transparent'
  96. }
  97. },
  98. label: {
  99. normal: {
  100. show: true,
  101. position: 'left',
  102. formatter: myRegression.expression,
  103. textStyle: {
  104. color: '#333',
  105. fontSize: 14
  106. }
  107. }
  108. },
  109. data: [{
  110. coord: myRegression.points[myRegression.points.length - 1]
  111. }]
  112. }
  113. }]
  114. });
  115. });
  116. </script>
  117. </body>
  118. </html>