dataZoom-rainfall.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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,
  11. body,
  12. #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. 'data/rainfall.json',
  23. 'echarts',
  24. 'echarts/chart/bar',
  25. 'echarts/chart/line',
  26. 'echarts/component/legend',
  27. 'echarts/component/tooltip',
  28. 'echarts/component/grid',
  29. 'echarts/component/axis',
  30. 'echarts/component/dataZoom'
  31. ], function (data, echarts) {
  32. chart = echarts.init(document.getElementById('main'), null, {
  33. renderer: 'canvas'
  34. });
  35. var xAxisData = [];
  36. var data1 = [];
  37. var data2 = [];
  38. var data3 = [];
  39. for (var i = 0; i < 20; i++) {
  40. xAxisData.push('类目' + i);
  41. data1.push(Math.random() * 2);
  42. data2.push(Math.random() * 2);
  43. data3.push(Math.random() * 2);
  44. }
  45. chart.setOption({
  46. tooltip: {
  47. trigger: 'axis',
  48. },
  49. legend: {
  50. data: ['降水量', '流量']
  51. },
  52. grid: {
  53. show: true,
  54. borderColor: '#ccc',
  55. borderWidth: 1,
  56. right: '15%'
  57. },
  58. xAxis: [
  59. {
  60. // data: ['类目1', '类目2', '类目3', '类目4', '类目5',]
  61. // data: xAxisData,
  62. type: 'category',
  63. boundaryGap: true,
  64. // splitLine: {show: false},
  65. axisLabel: {show: true},
  66. axisLine: {show: true},
  67. data: data.category
  68. }
  69. ],
  70. yAxis: [
  71. {
  72. // scale: true
  73. boundaryGap: false,
  74. splitLine: {show: false},
  75. axisLabel: {
  76. },
  77. axisLine: {
  78. lineStyle: {
  79. color: '#666'
  80. }
  81. }
  82. },
  83. {
  84. // scale: true
  85. boundaryGap: false,
  86. splitLine: {show: false},
  87. position: 'right',
  88. inverse: true,
  89. axisLabel: {
  90. textStyle: {
  91. color: '#666'
  92. }
  93. },
  94. axisLine: {
  95. lineStyle: {
  96. color: '#666'
  97. }
  98. }
  99. }
  100. ],
  101. series: [
  102. {
  103. name: '降水量',
  104. type: 'line',
  105. data: data.rainfall,
  106. itemStyle: {
  107. normal: {
  108. areaStyle: {}
  109. }
  110. }
  111. },
  112. {
  113. name: '流量',
  114. type: 'line',
  115. data: data.flow,
  116. yAxisIndex: 1,
  117. itemStyle: {
  118. normal: {
  119. areaStyle: {}
  120. }
  121. }
  122. },
  123. // {
  124. // name: 'bar3',
  125. // type: 'line',
  126. // data: data3
  127. // }
  128. ],
  129. dataZoom: [
  130. {
  131. show: true,
  132. orient: 'vertical',
  133. filterMode: 'empty',
  134. yAxisIndex: [0],
  135. left: 10
  136. },
  137. {
  138. show: true,
  139. xAxisIndex: [0],
  140. // realtime: false,
  141. },
  142. {
  143. show: true,
  144. orient: 'vertical',
  145. filterMode: 'empty',
  146. yAxisIndex: [1]
  147. }
  148. ]
  149. });
  150. })
  151. </script>
  152. </body>
  153. </html>