dataZoom-rainfall-connect.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="./lib/esl.js"></script>
  5. <script src="./lib/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实例。<br>
  34. 三个都会 dataZoom 同步。<br>
  35. 前两个会 tooltip 同步,第三个不 tooltip 同步。
  36. </div>
  37. <div id="main2"></div>
  38. <div id="main3"></div>
  39. <script>
  40. require([
  41. 'data/rainfall.json',
  42. 'echarts'
  43. // 'echarts/chart/bar',
  44. // 'echarts/chart/line',
  45. // 'echarts/component/legend',
  46. // 'echarts/component/tooltip',
  47. // 'echarts/component/grid',
  48. // 'echarts/component/axis',
  49. // 'echarts/component/toolbox',
  50. // 'echarts/component/dataZoomInside'
  51. ], function (data, echarts) {
  52. var chart1 = createChart1(data, echarts);
  53. var chart2 = createChart2(data, echarts);
  54. var chart3 = createChart3(data, echarts);
  55. echarts.connect([chart1, chart2, chart3]);
  56. // chart1.on('dataZoom', function (payload) {
  57. // chart2.dispatchAction({
  58. // type: 'dataZoom',
  59. // dataZoomIndex: 0,
  60. // range: payload.range
  61. // }, true);
  62. // });
  63. // chart2.on('dataZoom', function (payload) {
  64. // chart1.dispatchAction({
  65. // type: 'dataZoom',
  66. // dataZoomIndex: 0,
  67. // range: payload.range
  68. // }, true);
  69. // });
  70. });
  71. function createChart1(data, echarts) {
  72. var chart = echarts.init(document.getElementById('main'), null, {
  73. });
  74. chart.setOption({
  75. tooltip: {
  76. trigger: 'axis',
  77. },
  78. legend: {
  79. data: ['降水量']
  80. },
  81. grid: [
  82. {
  83. show: true,
  84. borderWidth: 0,
  85. left: 0,
  86. right: 0,
  87. top: 0,
  88. bottom: 0
  89. }
  90. ],
  91. toolbox: {
  92. feature: {
  93. saveAsImage: {}
  94. }
  95. },
  96. xAxis: [
  97. {
  98. // data: ['类目1', '类目2', '类目3', '类目4', '类目5',]
  99. // data: xAxisData,
  100. type: 'category',
  101. boundaryGap: true,
  102. // splitLine: {show: false},
  103. axisLabel: {show: true},
  104. splitLine: {show: false},
  105. axisLine: {
  106. show: true,
  107. // onZero: false
  108. },
  109. data: data.category
  110. }
  111. ],
  112. yAxis: [
  113. {
  114. boundaryGap: false,
  115. axisLabel: {
  116. },
  117. axisLine: {
  118. lineStyle: {
  119. color: '#666'
  120. }
  121. }
  122. }
  123. ],
  124. series: [
  125. {
  126. name: '降水量',
  127. type: 'line',
  128. data: data.rainfall,
  129. itemStyle: {
  130. normal: {
  131. areaStyle: {}
  132. }
  133. }
  134. }
  135. ],
  136. dataZoom: [
  137. {
  138. type: 'inside',
  139. start: 30,
  140. end: 40
  141. }
  142. ]
  143. });
  144. return chart;
  145. }
  146. function createChart2(data, echarts) {
  147. var chart = echarts.init(document.getElementById('main2'), null, {
  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. });
  220. chart.setOption({
  221. tooltip: {
  222. trigger: 'axis',
  223. },
  224. legend: {
  225. data: ['流量']
  226. },
  227. grid: [
  228. {
  229. show: true,
  230. borderWidth: 0,
  231. left: 0,
  232. right: 0,
  233. top: 0,
  234. bottom: 0
  235. }
  236. ],
  237. xAxis: [
  238. {
  239. type: 'category',
  240. boundaryGap: true,
  241. axisLabel: {show: true},
  242. splitLine: {show: false},
  243. axisLine: {
  244. show: true,
  245. },
  246. data: data.category
  247. }
  248. ],
  249. yAxis: [
  250. {
  251. boundaryGap: false,
  252. position: 'right',
  253. inverse: true,
  254. axisLabel: {
  255. textStyle: {
  256. color: '#666'
  257. }
  258. },
  259. axisLine: {
  260. lineStyle: {
  261. color: '#666'
  262. }
  263. }
  264. }
  265. ],
  266. series: [
  267. {
  268. name: 'NaN',
  269. type: 'line',
  270. data: data.flow.map(function () { return null; })
  271. },
  272. {
  273. name: '流量',
  274. type: 'line',
  275. data: data.flow,
  276. itemStyle: {
  277. normal: {
  278. areaStyle: {}
  279. }
  280. }
  281. }
  282. ],
  283. dataZoom: [
  284. {
  285. type: 'inside',
  286. start: 30,
  287. end: 40
  288. }
  289. ]
  290. });
  291. return chart;
  292. }
  293. </script>
  294. </body>
  295. </html>