markPoint.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. </head>
  7. <body>
  8. <style>
  9. html, body, #main {
  10. width: 100%;
  11. height: 100%;
  12. }
  13. </style>
  14. <div id="main"></div>
  15. <script>
  16. require([
  17. 'echarts',
  18. 'echarts/chart/line',
  19. 'echarts/component/legend',
  20. 'echarts/component/grid',
  21. 'echarts/component/tooltip',
  22. 'echarts/component/markPoint'
  23. ], function (echarts) {
  24. var chart = echarts.init(document.getElementById('main'), null, {
  25. renderer: 'canvas'
  26. });
  27. var xAxisData = [];
  28. var data1 = [];
  29. var data2 = [];
  30. for (var i = 0; i < 10; i++) {
  31. xAxisData.push('类目' + i);
  32. data1.push(+Math.random().toFixed(2));
  33. data2.push(+Math.random().toFixed(2));
  34. }
  35. if (console && console.log) {
  36. console.log(data1);
  37. console.log(data2);
  38. }
  39. chart.setOption({
  40. legend: {
  41. data: ['line-stack', 'line2-stack', 'line3']
  42. },
  43. tooltip: {
  44. trigger: 'axis',
  45. axisPointer: {
  46. type: 'line'
  47. }
  48. },
  49. xAxis: {
  50. // data: ['类目1', '类目2', '类目3', '类目4', '类目5',]
  51. data: xAxisData,
  52. boundaryGap: false,
  53. // inverse: true,
  54. splitArea: {
  55. show: true
  56. }
  57. },
  58. yAxis: {
  59. splitLine: {
  60. // show: false
  61. }
  62. },
  63. series: [
  64. {
  65. name: 'line-stack',
  66. type: 'line',
  67. stack: 'all',
  68. symbolSize: 6,
  69. areaStyle: {normal: {}},
  70. data: data1,
  71. markPoint: {
  72. data: [
  73. {
  74. name: '最大值',
  75. type: 'max',
  76. value: 1
  77. },
  78. {
  79. xAxis: '类目3',
  80. yAxis: 0.5,
  81. value: 2
  82. }
  83. ]
  84. }
  85. },
  86. {
  87. name: 'line2-stack',
  88. type: 'line',
  89. stack: 'all',
  90. symbolSize: 6,
  91. areaStyle: {normal: {}},
  92. data: data2,
  93. markPoint: {
  94. label: {
  95. normal: {
  96. formatter: function (param) {
  97. return param.name + ' ' + param.value;
  98. },
  99. textStyle: {
  100. color: '#000'
  101. },
  102. position: 'top'
  103. }
  104. },
  105. data: [
  106. {
  107. name: '最小值stack',
  108. type: 'min',
  109. value: 1
  110. },
  111. {
  112. name: '最大值stack',
  113. type: 'max',
  114. value: 1
  115. },
  116. {
  117. name: '平均值stack',
  118. type: 'average',
  119. value: 1
  120. }
  121. ]
  122. }
  123. },
  124. {
  125. name: 'line3',
  126. type: 'line',
  127. symbolSize: 6,
  128. data: data2,
  129. markPoint: {
  130. label: {
  131. normal: {
  132. formatter: function (param) {
  133. return param.name + ' ' + param.value;
  134. },
  135. textStyle: {
  136. color: '#000'
  137. },
  138. position: 'top'
  139. }
  140. },
  141. data: [
  142. {
  143. name: '000000000',
  144. coord: ['类目2', 0.6],
  145. value: 1
  146. },
  147. {
  148. name: '最小值',
  149. type: 'min',
  150. value: 1
  151. },
  152. {
  153. name: '最大值x',
  154. type: 'max',
  155. value: 1
  156. },
  157. {
  158. name: '最大值y',
  159. type: 'max',
  160. valueIndex: 0,
  161. value: 1
  162. },
  163. {
  164. name: '平均值',
  165. type: 'average',
  166. value: 1
  167. }
  168. ]
  169. }
  170. }
  171. ]
  172. });
  173. chart.on('click', function (params) {
  174. console.log(params, params.data);
  175. });
  176. })
  177. </script>
  178. </body>
  179. </html>