markLine.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/markLine'
  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. chart.setOption({
  36. legend: {
  37. data: ['line', 'line2']
  38. },
  39. tooltip: {
  40. trigger: 'axis',
  41. axisPointer: {
  42. type: 'line'
  43. }
  44. },
  45. xAxis: {
  46. // data: ['类目1', '类目2', '类目3', '类目4', '类目5',]
  47. data: xAxisData,
  48. boundaryGap: true,
  49. // inverse: true,
  50. splitArea: {
  51. show: true
  52. }
  53. },
  54. yAxis: {
  55. splitLine: {
  56. // show: false
  57. }
  58. },
  59. series: [{
  60. name: 'line',
  61. type: 'line',
  62. stack: 'all',
  63. symbolSize: 6,
  64. data: data1,
  65. markLine: {
  66. data: [{
  67. name: '平均值',
  68. type: 'average',
  69. valueIndex: 1
  70. }, {
  71. name: '指定值',
  72. yAxis: 1
  73. }, [{
  74. name: '标签位置为中间',
  75. type: 'min',
  76. label: {
  77. normal: {
  78. formatter: '{b}',
  79. position: 'middle'
  80. }
  81. }
  82. }, {
  83. name: '标签位置为中间',
  84. type: 'max'
  85. }]]
  86. }
  87. }, {
  88. name: 'line2',
  89. type: 'line',
  90. stack: 'all',
  91. symbolSize: 6,
  92. data: data2,
  93. markLine: {
  94. data: [{
  95. name: '平均值',
  96. type: 'average',
  97. valueIndex: 0
  98. }, {
  99. name: '指定值',
  100. xAxis: 3
  101. }]
  102. }
  103. }]
  104. });
  105. chart.on('click', function (params) {
  106. console.log(params, params.data);
  107. });
  108. });
  109. </script>
  110. </body>
  111. </html>