index2.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ECharts</title>
  6. <!-- 引入 echarts.js -->
  7. <script src="./js/echarts.js"></script>
  8. </head>
  9. <body>
  10. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  11. <div id="main" style="width: 600px;height:400px;"></div>
  12. <script type="text/javascript">
  13. // 基于准备好的dom,初始化echarts实例
  14. var myChart = echarts.init(document.getElementById('main'));
  15. // 指定图表的配置项和数据
  16. option = {
  17. backgroundColor: '#eee',
  18. dataZoom: [{
  19. show: true,
  20. realtime: true,
  21. start: 30,
  22. end: 70,
  23. // xAxisIndex: [0, 1],
  24. zoomOnMouseWheel: false,
  25. }],
  26. legend: {
  27. data: ['bar', 'bar2', 'bar3', 'bar4'],
  28. align: 'left',
  29. left: 10
  30. },
  31. brush: {
  32. toolbox: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'],
  33. xAxisIndex: 0
  34. },
  35. toolbox: {
  36. feature: {
  37. magicType: {
  38. type: ['stack', 'tiled']
  39. },
  40. dataView: {}
  41. }
  42. },
  43. tooltip: {},
  44. xAxis: {
  45. data: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8],
  46. position: "top",
  47. silent: false,
  48. axisLine: {
  49. onZero: true
  50. },
  51. splitLine: {
  52. show: false
  53. },
  54. splitArea: {
  55. show: false
  56. },
  57. axisTick: {
  58. show: false
  59. }
  60. },
  61. yAxis: [{
  62. inverse: true,
  63. splitArea: {
  64. show: false
  65. },
  66. splitLine: {
  67. show: false
  68. }
  69. }, {
  70. type: 'value',
  71. name: '收视率%',
  72. splitLine: {
  73. show: false
  74. }
  75. }],
  76. grid: {
  77. left: 0
  78. },
  79. series: [{
  80. name: 'bar',
  81. type: 'bar',
  82. stack: 'one',
  83. data: [-1, -2, -3, -4, -5, -6, -7, -8, -1, -2, -3, -4, -5, -6, -7, -8, -1, -2, -3, -4, -5, -6, -7, -8],
  84. }, {
  85. name: 'bar2',
  86. type: 'bar',
  87. stack: 'one',
  88. data: [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8],
  89. }, {
  90. name: '收视率%',
  91. type: 'line',
  92. yAxisIndex: 1,
  93. hoverAnimation: false,
  94. data: [11, 21, 31, 41, 51, 61, 71, 81, 11, 21, 31, 41, 51, 61, 71, 81, 11, 21, 31, 41, 51, 61, 71, 81]
  95. }]
  96. };
  97. // 使用刚指定的配置项和数据显示图表。
  98. myChart.setOption(option);
  99. myChart.on('datazoom', function(params) {
  100. var xAxis = myChart.getModel().option.xAxis[0];
  101. var endTime = xAxis.data[xAxis.rangeStart];
  102. console.log(endTime);
  103. });
  104. </script>
  105. </body>
  106. </html>
  107. <!--option = {
  108. // backgroundColor: 'rgba(0,0,0,.8)',
  109. legend: {
  110. data: ['流入', '流出', '收视率%'],
  111. bottom: '10%',
  112. left: 'center',
  113. textStyle: {
  114. color: '#000000',
  115. fontSize: 12,
  116. },
  117. },
  118. title: {
  119. text: '流入/流出',
  120. left: 5,
  121. bottom: '13%',
  122. textStyle: {
  123. color: '#000000',
  124. fontSize: 12,
  125. },
  126. },
  127. tooltip: {
  128. show: true,
  129. trigger: 'axis'
  130. },
  131. xAxis: {
  132. data: canvas.Xdata(time),
  133. position: "top",
  134. axisLine: {
  135. show: false,
  136. onZero: true,
  137. },
  138. splitLine: {
  139. show: false
  140. },
  141. splitArea: {
  142. show: false
  143. },
  144. axisTick: {
  145. show: false
  146. },
  147. axisLabel: {
  148. rotate: -80,
  149. interval: 0,
  150. textStyle: {
  151. color: '#000000',
  152. }
  153. },
  154. },
  155. yAxis: [{
  156. type: 'value',
  157. //name:'流入/流出',
  158. offset: -5,
  159. axisLine: {
  160. show: false
  161. },
  162. splitLine: {
  163. show: false
  164. },
  165. splitArea: {
  166. show: false
  167. },
  168. axisTick: {
  169. show: false
  170. },
  171. axisLabel: {
  172. textStyle: {
  173. color: '#000000',
  174. }
  175. },
  176. nameTextStyle: {
  177. color: '#000000',
  178. },
  179. }, {
  180. type: 'value',
  181. scale: true,
  182. offset: -30,
  183. axisLine: {
  184. show: false
  185. },
  186. splitLine: {
  187. show: false
  188. },
  189. splitArea: {
  190. show: false
  191. },
  192. axisTick: {
  193. show: false
  194. },
  195. axisLabel: {
  196. textStyle: {
  197. color: '#000000',
  198. }
  199. },
  200. nameLocation: 'middle',
  201. nameTextStyle: {
  202. color: '#000000',
  203. },
  204. }],
  205. grid: {
  206. left: '12%',
  207. width: '85%',
  208. height: '50%',
  209. },
  210. series: [{
  211. name: '流入',
  212. type: 'bar',
  213. stack: 'one',
  214. barWidth: 5,
  215. itemStyle: itemStyle,
  216. label: {
  217. emphasis: {
  218. show: true,
  219. position: 'top',
  220. textStyle: {
  221. color: '#000000',
  222. fontSize: 14,
  223. },
  224. },
  225. },
  226. data: line2
  227. }, {
  228. name: '流出',
  229. type: 'bar',
  230. stack: 'one',
  231. barWidth: 5,
  232. itemStyle: itemStyle,
  233. data: line1
  234. }, {
  235. name: '收视率%',
  236. type: 'line',
  237. stack: 'two',
  238. yAxisIndex: 1,
  239. itemStyle: itemStyle,
  240. data: line3
  241. },
  242. ]
  243. };-->