dataZoom-toolbox.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="lib/esl.js"></script>
  6. <script src="lib/config.js"></script>
  7. <script src="lib/jquery.min.js"></script>
  8. <script src="lib/facePrint.js"></script>
  9. <meta name="viewport" content="width=device-width, initial-scale=1" />
  10. <link rel="stylesheet" href="lib/reset.css">
  11. </head>
  12. <body>
  13. <style>
  14. .chart {
  15. position: relative;
  16. height: 500px;
  17. max-width: 1000px;
  18. margin: 0 auto;
  19. }
  20. h2 {
  21. text-align: center;
  22. font-size: 16px;
  23. line-height: 40px;
  24. font-weight: normal;
  25. background: #078302;
  26. color: #eee;
  27. }
  28. </style>
  29. <h2>scatter</h2>
  30. <div class="chart" id="main1"></div>
  31. <h2>Test: (1) click zoom btn (2) select (3) click zoom btn, expect: not change</h2>
  32. <div class="chart" id="main-test-y-range"></div>
  33. <h2>Multiple Y axis (default)</h2>
  34. <div class="chart" id="main-multiple-y-axis-default"></div>
  35. <h2>Specify Y axis (yAxisIndex: [1, 2, 4], xAxisIndex: false, should be 'lineY' brush)</h2>
  36. <div class="chart" id="main-specify-y-axis"></div>
  37. <h2>Specify Y axis (yAxisIndex: false, should be 'lineX' brush)</h2>
  38. <div class="chart" id="main-specify-x-axis"></div>
  39. <script>
  40. var lastChart;
  41. var globalColor = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'];
  42. function makeChart(id, option, cb) {
  43. require([
  44. 'echarts'
  45. // 'echarts/model/globalDefault',
  46. // 'echarts/chart/scatter',
  47. // 'echarts/chart/line',
  48. // 'echarts/chart/bar',
  49. // 'echarts/chart/scatter',
  50. // 'echarts/component/grid',
  51. // 'echarts/component/markLine',
  52. // 'echarts/component/legend',
  53. // 'echarts/component/tooltip',
  54. // 'echarts/component/toolbox',
  55. // 'echarts/component/dataZoom'
  56. ], function (echarts, globalDefault) {
  57. var main = document.getElementById(id);
  58. if (main) {
  59. var chartMain = document.createElement('div');
  60. chartMain.style.cssText = 'height:100%';
  61. main.appendChild(chartMain);
  62. var chart = lastChart = echarts.init(chartMain);
  63. if (typeof option === 'function') {
  64. option = option(echarts, globalDefault);
  65. }
  66. chart.setOption(option);
  67. window.addEventListener('resize', chart.resize);
  68. cb && cb(echarts, chart);
  69. }
  70. });
  71. }
  72. </script>
  73. <script>
  74. var data1 = [];
  75. var data2 = [];
  76. var data3 = [];
  77. function random(max) {
  78. return (Math.random() * max).toFixed(3);
  79. };
  80. for (var i = 0; i < 100; i++) {
  81. data1.push([random(15), random(10), random(1)]);
  82. // data1.push([i, 10, i]);
  83. data2.push([random(10), random(10), random(1)]);
  84. data3.push([random(15), random(10), random(1)]);
  85. }
  86. makeChart('main1', {
  87. legend: {
  88. data: ['scatter', 'scatter2', 'scatter3']
  89. },
  90. animationDuration: 1000,
  91. animationDurationUpdate: 1000,
  92. toolbox: {
  93. feature: {
  94. dataView: {},
  95. dataZoom: {
  96. show: true,
  97. yAxisIndex: null
  98. },
  99. restore: {show: true},
  100. saveAsImage: {}
  101. }
  102. },
  103. tooltip: {
  104. },
  105. xAxis: {
  106. type: 'value',
  107. min: 'dataMin',
  108. max: 'dataMax',
  109. splitLine: {
  110. show: true
  111. }
  112. },
  113. yAxis: {
  114. type: 'value',
  115. min: 'dataMin',
  116. max: 'dataMax',
  117. splitLine: {
  118. show: true
  119. }
  120. },
  121. dataZoom: [
  122. {
  123. show: true,
  124. xAxisIndex: [0],
  125. start: 10,
  126. end: 70
  127. },
  128. {
  129. show: true,
  130. yAxisIndex: [0],
  131. start: 0,
  132. end: 20
  133. },
  134. {
  135. type: 'inside',
  136. xAxisIndex: [0],
  137. start: 10,
  138. end: 70
  139. },
  140. {
  141. type: 'inside',
  142. yAxisIndex: [0],
  143. start: 0,
  144. end: 20
  145. }
  146. ],
  147. series: [
  148. {
  149. name: 'scatter',
  150. type: 'scatter',
  151. itemStyle: {
  152. normal: {
  153. opacity: 0.8,
  154. }
  155. },
  156. symbolSize: function (val) {
  157. return val[2] * 40;
  158. },
  159. data: data1
  160. },
  161. {
  162. name: 'scatter2',
  163. type: 'scatter',
  164. itemStyle: {
  165. normal: {
  166. opacity: 0.8
  167. }
  168. },
  169. symbolSize: function (val) {
  170. return val[2] * 40;
  171. },
  172. data: data2
  173. },
  174. {
  175. name: 'scatter3',
  176. type: 'scatter',
  177. itemStyle: {
  178. normal: {
  179. opacity: 0.8,
  180. }
  181. },
  182. symbolSize: function (val) {
  183. return val[2] * 40;
  184. },
  185. data: data3
  186. }
  187. ]
  188. });
  189. </script>
  190. <script>
  191. makeChart('main-test-y-range', function (echarts, globalDefault) {
  192. return {
  193. tooltip: {},
  194. toolbox: {
  195. feature: {
  196. dataZoom: {},
  197. restore: {}
  198. }
  199. },
  200. legend: {
  201. data: ['A1', 'A2', 'A3', 'B1', 'B2']
  202. },
  203. grid: [{
  204. left: 40,
  205. width: 300,
  206. }],
  207. xAxis: [{
  208. data: ['z', 'y', 'x', 'w', 'v', 'u']
  209. }],
  210. yAxis: [{
  211. type: 'value',
  212. position: 'left',
  213. axisLine: {
  214. lineStyle: {
  215. color: globalColor[0]
  216. }
  217. }
  218. }, {
  219. type: 'value',
  220. position: 'right',
  221. axisLine: {
  222. lineStyle: {
  223. color: globalColor[1]
  224. }
  225. }
  226. }, {
  227. type: 'value',
  228. position: 'right',
  229. offset: 80,
  230. axisLine: {
  231. lineStyle: {
  232. color: globalColor[2]
  233. }
  234. }
  235. }],
  236. dataZoom: [{
  237. type: 'slider',
  238. height: 20
  239. }, {
  240. type: 'slider',
  241. yAxisIndex: 1,
  242. orient: 'vertical',
  243. left: 365,
  244. width: 20
  245. }, {
  246. type: 'slider',
  247. yAxisIndex: 2,
  248. orient: 'vertical',
  249. left: 445,
  250. width: 20
  251. }],
  252. series: [{
  253. name: 'A1',
  254. type: 'line',
  255. data: [5, 1, 5, 1, 5, 10]
  256. }, {
  257. name: 'A2',
  258. type: 'line',
  259. yAxisIndex: 1,
  260. data: [1, 5, 1, 5, 1, 10]
  261. }, {
  262. name: 'A3',
  263. type: 'line',
  264. yAxisIndex: 2,
  265. data: [3, 8, 1, 4, 2, 5]
  266. }]
  267. };
  268. });
  269. </script>
  270. <script>
  271. makeChart('main-multiple-y-axis-default', function (echarts, globalDefault) {
  272. return {
  273. tooltip: {},
  274. toolbox: {
  275. feature: {
  276. dataZoom: {},
  277. restore: {}
  278. }
  279. },
  280. legend: {
  281. data: ['A1', 'A2', 'A3', 'B1', 'B2']
  282. },
  283. grid: [{
  284. left: 40,
  285. width: 300,
  286. }, {
  287. left: 550,
  288. right: 40
  289. }],
  290. xAxis: [{
  291. data: ['z', 'y', 'x', 'w', 'v', 'u']
  292. }, {
  293. data: ['z', 'y', 'x', 'w', 'v', 'u'],
  294. gridIndex: 1
  295. }],
  296. yAxis: [{
  297. type: 'value',
  298. position: 'left',
  299. axisLine: {
  300. lineStyle: {
  301. color: globalColor[0]
  302. }
  303. }
  304. }, {
  305. type: 'value',
  306. position: 'right',
  307. axisLine: {
  308. lineStyle: {
  309. color: globalColor[1]
  310. }
  311. }
  312. }, {
  313. type: 'value',
  314. position: 'right',
  315. offset: 80,
  316. axisLine: {
  317. lineStyle: {
  318. color: globalColor[2]
  319. }
  320. }
  321. }, {
  322. type: 'value',
  323. position: 'left',
  324. gridIndex: 1,
  325. boundaryGap: ['20%', '20%'],
  326. axisLine: {
  327. lineStyle: {
  328. color: globalColor[3]
  329. }
  330. }
  331. }, {
  332. type: 'value',
  333. position: 'right',
  334. gridIndex: 1,
  335. boundaryGap: ['20%', '20%'],
  336. axisLine: {
  337. lineStyle: {
  338. color: globalColor[4]
  339. }
  340. }
  341. }],
  342. dataZoom: [{
  343. type: 'slider',
  344. height: 20
  345. }, {
  346. type: 'slider',
  347. yAxisIndex: 1,
  348. orient: 'vertical',
  349. left: 365,
  350. width: 20
  351. }, {
  352. type: 'slider',
  353. yAxisIndex: 2,
  354. orient: 'vertical',
  355. left: 445,
  356. width: 20
  357. }],
  358. series: [{
  359. name: 'A1',
  360. type: 'line',
  361. data: [5, 1, 5, 1, 5, 10]
  362. }, {
  363. name: 'A2',
  364. type: 'line',
  365. yAxisIndex: 1,
  366. data: [1, 5, 1, 5, 1, 10]
  367. }, {
  368. name: 'A3',
  369. type: 'line',
  370. yAxisIndex: 2,
  371. data: [3, 8, 1, 4, 2, 5]
  372. }, {
  373. name: 'B1',
  374. type: 'line',
  375. xAxisIndex: 1,
  376. yAxisIndex: 3,
  377. data: [5, 1, 5, 1, 5, 3]
  378. }, {
  379. name: 'B2',
  380. type: 'line',
  381. xAxisIndex: 1,
  382. yAxisIndex: 4,
  383. data: [1, 5, 1, 5, 1, 10]
  384. }]
  385. };
  386. });
  387. </script>
  388. <script>
  389. makeChart('main-specify-y-axis', function (echarts, globalDefault) {
  390. return {
  391. tooltip: {},
  392. toolbox: {
  393. feature: {
  394. dataZoom: {
  395. yAxisIndex: [1, 2, 4],
  396. xAxisIndex: false
  397. },
  398. restore: {}
  399. }
  400. },
  401. legend: {
  402. data: ['A1', 'A2', 'A3', 'B1', 'B2']
  403. },
  404. grid: [{
  405. left: 40,
  406. width: 300,
  407. }, {
  408. left: 550,
  409. right: 40
  410. }],
  411. xAxis: [{
  412. data: ['z', 'y', 'x', 'w', 'v', 'u']
  413. }, {
  414. data: ['z', 'y', 'x', 'w', 'v', 'u'],
  415. gridIndex: 1
  416. }],
  417. yAxis: [{
  418. type: 'value',
  419. position: 'left',
  420. axisLine: {
  421. lineStyle: {
  422. color: globalColor[0]
  423. }
  424. }
  425. }, {
  426. type: 'value',
  427. position: 'right',
  428. axisLine: {
  429. lineStyle: {
  430. color: globalColor[1]
  431. }
  432. }
  433. }, {
  434. type: 'value',
  435. position: 'right',
  436. offset: 80,
  437. axisLine: {
  438. lineStyle: {
  439. color: globalColor[2]
  440. }
  441. }
  442. }, {
  443. type: 'value',
  444. position: 'left',
  445. gridIndex: 1,
  446. boundaryGap: ['20%', '20%'],
  447. axisLine: {
  448. lineStyle: {
  449. color: globalColor[3]
  450. }
  451. }
  452. }, {
  453. type: 'value',
  454. position: 'right',
  455. gridIndex: 1,
  456. boundaryGap: ['20%', '20%'],
  457. axisLine: {
  458. lineStyle: {
  459. color: globalColor[4]
  460. }
  461. }
  462. }],
  463. series: [{
  464. name: 'A1',
  465. type: 'line',
  466. data: [5, 1, 5, 1, 5, 10]
  467. }, {
  468. name: 'A2',
  469. type: 'line',
  470. yAxisIndex: 1,
  471. data: [1, 5, 1, 5, 1, 10]
  472. }, {
  473. name: 'A3',
  474. type: 'line',
  475. yAxisIndex: 2,
  476. data: [3, 8, 1, 4, 2, 5]
  477. }, {
  478. name: 'B1',
  479. type: 'line',
  480. xAxisIndex: 1,
  481. yAxisIndex: 3,
  482. data: [5, 1, 5, 1, 5, 10]
  483. }, {
  484. name: 'B2',
  485. type: 'line',
  486. xAxisIndex: 1,
  487. yAxisIndex: 4,
  488. data: [1, 5, 1, 5, 1, 10]
  489. }]
  490. };
  491. });
  492. </script>
  493. <script>
  494. makeChart('main-specify-x-axis', function (echarts, globalDefault) {
  495. return {
  496. tooltip: {},
  497. toolbox: {
  498. feature: {
  499. dataZoom: {
  500. yAxisIndex: false
  501. },
  502. restore: {}
  503. }
  504. },
  505. legend: {
  506. data: ['A1', 'A2', 'A3', 'B1', 'B2']
  507. },
  508. grid: [{
  509. left: 40,
  510. width: 300,
  511. }, {
  512. left: 550,
  513. right: 40
  514. }],
  515. xAxis: [{
  516. data: ['z', 'y', 'x', 'w', 'v', 'u']
  517. }, {
  518. data: ['z', 'y', 'x', 'w', 'v', 'u'],
  519. gridIndex: 1
  520. }],
  521. yAxis: [{
  522. type: 'value',
  523. position: 'left',
  524. axisLine: {
  525. lineStyle: {
  526. color: globalColor[0]
  527. }
  528. }
  529. }, {
  530. type: 'value',
  531. position: 'right',
  532. axisLine: {
  533. lineStyle: {
  534. color: globalColor[1]
  535. }
  536. }
  537. }, {
  538. type: 'value',
  539. position: 'right',
  540. offset: 80,
  541. axisLine: {
  542. lineStyle: {
  543. color: globalColor[2]
  544. }
  545. }
  546. }, {
  547. type: 'value',
  548. position: 'left',
  549. gridIndex: 1,
  550. boundaryGap: ['20%', '20%'],
  551. axisLine: {
  552. lineStyle: {
  553. color: globalColor[3]
  554. }
  555. }
  556. }, {
  557. type: 'value',
  558. position: 'right',
  559. gridIndex: 1,
  560. boundaryGap: ['20%', '20%'],
  561. axisLine: {
  562. lineStyle: {
  563. color: globalColor[4]
  564. }
  565. }
  566. }],
  567. series: [{
  568. name: 'A1',
  569. type: 'line',
  570. data: [5, 1, 5, 1, 5, 10]
  571. }, {
  572. name: 'A2',
  573. type: 'line',
  574. yAxisIndex: 1,
  575. data: [1, 5, 1, 5, 1, 10]
  576. }, {
  577. name: 'A3',
  578. type: 'line',
  579. yAxisIndex: 2,
  580. data: [3, 8, 1, 4, 2, 5]
  581. }, {
  582. name: 'B1',
  583. type: 'line',
  584. xAxisIndex: 1,
  585. yAxisIndex: 3,
  586. data: [5, 1, 5, 1, 5, 10]
  587. }, {
  588. name: 'B2',
  589. type: 'line',
  590. xAxisIndex: 1,
  591. yAxisIndex: 4,
  592. data: [1, 5, 1, 5, 1, 10]
  593. }]
  594. };
  595. });
  596. </script>
  597. </body>
  598. </html>