dataZoom-rainfall-connect.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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,
  10. body,
  11. #main,
  12. #main2,
  13. #main3 {
  14. width: 90%;
  15. height: 200px;
  16. margin: 0;
  17. padding: 0;
  18. }
  19. #main2 {
  20. width: 75%;
  21. }
  22. #main3 {
  23. width: 50%;
  24. }
  25. #middle {
  26. text-align: center;
  27. padding: 10px;
  28. background: #d4e8f1;
  29. }
  30. </style>
  31. <div id="main"></div>
  32. <div id="middle">
  33. 上面是降水量,下面是流量。这是两个echarts实例。
  34. </div>
  35. <div id="main2"></div>
  36. <div id="main3"></div>
  37. <script>
  38. require([
  39. 'data/rainfall.json',
  40. 'echarts',
  41. 'echarts/chart/bar',
  42. 'echarts/chart/line',
  43. 'echarts/component/legend',
  44. 'echarts/component/tooltip',
  45. 'echarts/component/grid',
  46. 'echarts/component/axis',
  47. 'echarts/component/toolbox',
  48. 'echarts/component/dataZoomInside'
  49. ], function (data, echarts) {
  50. var chart1 = createChart1(data, echarts);
  51. var chart2 = createChart2(data, echarts);
  52. var chart3 = createChart3(data, echarts);
  53. echarts.connect([chart1, chart2, chart3]);
  54. // chart1.on('dataZoom', function (payload) {
  55. // chart2.dispatchAction({
  56. // type: 'dataZoom',
  57. // dataZoomIndex: 0,
  58. // range: payload.range
  59. // }, true);
  60. // });
  61. // chart2.on('dataZoom', function (payload) {
  62. // chart1.dispatchAction({
  63. // type: 'dataZoom',
  64. // dataZoomIndex: 0,
  65. // range: payload.range
  66. // }, true);
  67. // });
  68. });
  69. function createChart1(data, echarts) {
  70. var chart = echarts.init(document.getElementById('main'), null, {
  71. renderer: 'canvas'
  72. });
  73. chart.setOption({
  74. tooltip: {
  75. trigger: 'axis',
  76. },
  77. legend: {
  78. data: ['降水量']
  79. },
  80. grid: [
  81. {
  82. show: true,
  83. borderWidth: 0,
  84. left: 0,
  85. right: 0,
  86. top: 0,
  87. bottom: 0
  88. }
  89. ],
  90. toolbox: {
  91. feature: {
  92. saveAsImage: {}
  93. }
  94. },
  95. xAxis: [
  96. {
  97. // data: ['类目1', '类目2', '类目3', '类目4', '类目5',]
  98. // data: xAxisData,
  99. type: 'category',
  100. boundaryGap: true,
  101. // splitLine: {show: false},
  102. axisLabel: {show: true},
  103. splitLine: {show: false},
  104. axisLine: {
  105. show: true,
  106. // onZero: false
  107. },
  108. data: data.category
  109. }
  110. ],
  111. yAxis: [
  112. {
  113. boundaryGap: false,
  114. axisLabel: {
  115. },
  116. axisLine: {
  117. lineStyle: {
  118. color: '#666'
  119. }
  120. }
  121. }
  122. ],
  123. series: [
  124. {
  125. name: '降水量',
  126. type: 'line',
  127. data: data.rainfall,
  128. itemStyle: {
  129. normal: {
  130. areaStyle: {}
  131. }
  132. }
  133. }
  134. ],
  135. dataZoom: [
  136. {
  137. type: 'inside',
  138. start: 30,
  139. end: 40
  140. }
  141. ]
  142. });
  143. return chart;
  144. }
  145. function createChart2(data, echarts) {
  146. var chart = echarts.init(document.getElementById('main2'), null, {
  147. renderer: 'canvas'
  148. });
  149. chart.setOption({
  150. tooltip: {
  151. trigger: 'axis',
  152. },
  153. legend: {
  154. data: ['流量']
  155. },
  156. grid: [
  157. {
  158. show: true,
  159. borderWidth: 0,
  160. left: 0,
  161. right: 0,
  162. top: 0,
  163. bottom: 0
  164. }
  165. ],
  166. xAxis: [
  167. {
  168. type: 'category',
  169. boundaryGap: true,
  170. axisLabel: {show: true},
  171. splitLine: {show: false},
  172. axisLine: {
  173. show: true,
  174. },
  175. data: data.category
  176. }
  177. ],
  178. yAxis: [
  179. {
  180. boundaryGap: false,
  181. position: 'right',
  182. inverse: true,
  183. axisLabel: {
  184. textStyle: {
  185. color: '#666'
  186. }
  187. },
  188. axisLine: {
  189. lineStyle: {
  190. color: '#666'
  191. }
  192. }
  193. }
  194. ],
  195. series: [
  196. {
  197. name: '流量',
  198. type: 'line',
  199. data: data.flow,
  200. itemStyle: {
  201. normal: {
  202. areaStyle: {}
  203. }
  204. }
  205. }
  206. ],
  207. dataZoom: [
  208. {
  209. type: 'inside',
  210. start: 30,
  211. end: 40
  212. }
  213. ]
  214. });
  215. return chart;
  216. }
  217. function createChart3(data, echarts) {
  218. var chart = echarts.init(document.getElementById('main3'), null, {
  219. renderer: 'canvas'
  220. });
  221. chart.setOption({
  222. tooltip: {
  223. trigger: 'axis',
  224. },
  225. legend: {
  226. data: ['流量']
  227. },
  228. grid: [
  229. {
  230. show: true,
  231. borderWidth: 0,
  232. left: 0,
  233. right: 0,
  234. top: 0,
  235. bottom: 0
  236. }
  237. ],
  238. xAxis: [
  239. {
  240. type: 'category',
  241. boundaryGap: true,
  242. axisLabel: {show: true},
  243. splitLine: {show: false},
  244. axisLine: {
  245. show: true,
  246. },
  247. data: data.category
  248. }
  249. ],
  250. yAxis: [
  251. {
  252. boundaryGap: false,
  253. position: 'right',
  254. inverse: true,
  255. axisLabel: {
  256. textStyle: {
  257. color: '#666'
  258. }
  259. },
  260. axisLine: {
  261. lineStyle: {
  262. color: '#666'
  263. }
  264. }
  265. }
  266. ],
  267. series: [
  268. {
  269. name: '流量',
  270. type: 'line',
  271. data: data.flow,
  272. itemStyle: {
  273. normal: {
  274. areaStyle: {}
  275. }
  276. }
  277. }
  278. ],
  279. dataZoom: [
  280. {
  281. type: 'inside',
  282. start: 30,
  283. end: 40
  284. }
  285. ]
  286. });
  287. return chart;
  288. }
  289. </script>
  290. </body>
  291. </html>