axis.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. </head>
  8. <body>
  9. <style>
  10. html, body, #main {
  11. width: 100%;
  12. height: 100%;
  13. }
  14. </style>
  15. <div id="main"></div>
  16. <script>
  17. require([
  18. 'echarts',
  19. 'echarts/util/graphic',
  20. 'echarts/chart/line',
  21. 'echarts/component/legend',
  22. 'echarts/component/grid',
  23. 'echarts/component/tooltip'
  24. ], function (echarts, graphic) {
  25. var chart = echarts.init(document.getElementById('main'), null, {
  26. renderer: 'canvas'
  27. });
  28. var xAxisData = [];
  29. var data1 = [];
  30. var data2 = [];
  31. var data3 = [];
  32. for (var i = 0; i < 5; i++) {
  33. xAxisData.push('类目' + i);
  34. data1.push((-Math.random() - 0.2).toFixed(3));
  35. data2.push((Math.random() + 0.3).toFixed(3));
  36. data3.push((Math.random() + 0.2).toFixed(3));
  37. }
  38. xAxisData.push({
  39. value: '类目' + i,
  40. textStyle: {
  41. color: 'red'
  42. }
  43. });
  44. data1.push('-');
  45. data2.push('-');
  46. data3.push('-');
  47. for (; i < 10; i++) {
  48. xAxisData.push('类目' + i);
  49. data1.push((-Math.random() - 0.2).toFixed(3));
  50. data2.push((Math.random() + 0.3).toFixed(3));
  51. data3.push((Math.random() + 0.2).toFixed(3));
  52. }
  53. var itemStyle = {
  54. normal: {
  55. // borderColor: 'white',
  56. // borderWidth: 3,
  57. // shadowBlur: 10,
  58. // shadowOffsetX: 0,
  59. // shadowOffsetY: 5,
  60. // shadowColor: 'rgba(0, 0, 0, 0.4)',
  61. lineStyle: {
  62. width: 2
  63. // shadowBlur: 10,
  64. // shadowOffsetX: 0,
  65. // shadowOffsetY: 5,
  66. // shadowColor: 'rgba(0, 0, 0, 0.4)'
  67. },
  68. areaStyle: {
  69. }
  70. }
  71. };
  72. chart.setOption({
  73. legend: {
  74. data: ['line', 'line2', 'line3']
  75. },
  76. tooltip: {
  77. trigger: 'axis',
  78. axisPointer: {
  79. type: 'line'
  80. }
  81. },
  82. xAxis: {
  83. // data: ['类目1', '类目2', '类目3', '类目4', '类目5',]
  84. data: xAxisData,
  85. boundaryGap: false,
  86. // inverse: true,
  87. splitArea: {
  88. show: true
  89. }
  90. },
  91. yAxis: {
  92. boundaryGap: [0, 0],
  93. splitLine: {
  94. show: false
  95. }
  96. },
  97. series: [{
  98. name: 'line',
  99. type: 'line',
  100. stack: 'all',
  101. symbolSize: 10,
  102. data: data1,
  103. itemStyle: itemStyle,
  104. smooth: true
  105. }, {
  106. name: 'line2',
  107. type: 'line',
  108. stack: 'all',
  109. symbolSize: 10,
  110. data: data2,
  111. itemStyle: itemStyle,
  112. smooth: true
  113. }, {
  114. name: 'line3',
  115. type: 'line',
  116. stack: 'all',
  117. symbolSize: 10,
  118. data: data3,
  119. itemStyle: itemStyle,
  120. areaStyle: {
  121. normal: {
  122. color: new graphic.LinearGradient(0, 0, 0, 1, [{
  123. offset: 0,
  124. color: 'red'
  125. }, {
  126. offset: 1,
  127. color: 'black'
  128. }])
  129. }
  130. },
  131. smooth: true
  132. }]
  133. });
  134. });
  135. </script>
  136. </body>
  137. </html>