dataset-category.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. <!DOCTYPE html>
  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/testHelper.js"></script>
  8. <meta name="viewport" content="width=device-width, initial-scale=1" />
  9. <link rel="stylesheet" href="lib/reset.css" />
  10. </head>
  11. <body>
  12. <style>
  13. .test-title {
  14. background: rgb(97, 17, 97);
  15. }
  16. .test-chart {
  17. height: 400px;
  18. }
  19. </style>
  20. <div id="specify-dimensions"></div>
  21. <div id="key-columns"></div>
  22. <div id="category-no-encode-two-value-axis"></div>
  23. <div id="category-no-axis-data-multi"></div>
  24. <div id="category-no-encode-no-axis-data-single"></div>
  25. <div id="category-no-encode-has-axis-data"></div>
  26. <div id="category"></div>
  27. <div id="two-value-axes"></div>
  28. <div id="empty-data"></div>
  29. <div id="dynamic-category"></div>
  30. <div id="dynamic-time"></div>
  31. <script>
  32. var keyColumnsDrink = {
  33. 'product': ['2012', '2013', '2014', '2015', '2016', '2017'],
  34. 'Matcha Latte': [41.1, 30.4, 65.1, 53.3, 83.8, 98.7],
  35. 'Milk Tea': [86.5, 92.1, 85.7, 83.1, 73.4, 55.1],
  36. 'Cheese Cocoa': [24.1, 67.2, 79.5, 86.4, 65.2, 82.5],
  37. 'Walnut Brownie': [55.2, 67.1, 69.2, 72.4, 53.9, 39.1]
  38. };
  39. </script>
  40. <script>
  41. require([
  42. 'echarts'
  43. ], function (echarts) {
  44. var source = [
  45. [21, 120, 220, 150, 320, 820],
  46. [31, 132, 182, 232, 332, 932],
  47. [41, 101, 191, 201, 301, 901],
  48. [51, 134, 234, 154, 334, 934],
  49. [61, 90, 290, 190, 309, 1290],
  50. [71, 230, 330, 330, 330, 1330],
  51. [81, 210, 310, 410, 320, 1320]
  52. ];
  53. var option = {
  54. legend: {},
  55. tooltip: {trigger: 'axis'},
  56. grid: {},
  57. xAxis: {},
  58. yAxis: {},
  59. dataZoom: [{}, {type: 'inside'}],
  60. dataset: [{
  61. dimensions: ['G', 'H', 'I', 'Q', 'R'],
  62. // sourceHeader: true,
  63. source: source
  64. }],
  65. series: [
  66. {type:'scatter', label: {show: true, position: 'top', textBorderWidth: 2, textBorderColor: '#fff'}, dimensions: ['cccccccccc', 'ddddddddddd']},
  67. {type:'scatter', label: {show: true, position: 'top', textBorderWidth: 2, textBorderColor: '#fff'}},
  68. {type:'scatter', label: {show: true, position: 'top', textBorderWidth: 2, textBorderColor: '#fff'}, sourceHeader: true}
  69. ]
  70. };
  71. testHelper.create(echarts, 'specify-dimensions', {
  72. title: 'speify dimensions',
  73. dataTable: source,
  74. option: option,
  75. info: {
  76. dimensions: option.dataset[0].dimensions,
  77. serise: option.series
  78. }
  79. });
  80. });
  81. </script>
  82. <script>
  83. require([
  84. 'echarts'
  85. ], function (echarts) {
  86. var option = {
  87. legend: {},
  88. tooltip: {trigger: 'axis'},
  89. grid: {},
  90. xAxis: {type: 'category'},
  91. yAxis: {},
  92. dataset: [{
  93. source: keyColumnsDrink
  94. }],
  95. series: [
  96. {type:'line'},
  97. {type:'line'},
  98. {type:'line'}
  99. ]
  100. };
  101. testHelper.create(echarts, 'key-columns', {
  102. title: 'category: no encode declared, two value axis',
  103. dataTable: keyColumnsDrink,
  104. option: option
  105. });
  106. });
  107. </script>
  108. <script>
  109. require([
  110. 'echarts'
  111. ], function (echarts) {
  112. var source = [
  113. [21, 120, 220, 150, 320, 820],
  114. [21, 132, 182, 232, 332, 932],
  115. [21, 101, 191, 201, 301, 901],
  116. [21, 134, 234, 154, 334, 934],
  117. [21, 90, 290, 190, 309, 1290],
  118. [21, 230, 330, 330, 330, 1330],
  119. [21, 210, 310, 410, 320, 1320]
  120. ];
  121. var option = {
  122. legend: {
  123. data: ['A', 'B', 'C']
  124. },
  125. tooltip: {trigger: 'axis'},
  126. grid: {
  127. left: '3%',
  128. right: '4%',
  129. bottom: '3%',
  130. containLabel: true
  131. },
  132. xAxis: {},
  133. yAxis: {},
  134. dataset: [{
  135. source: source
  136. }],
  137. series: [
  138. {
  139. name:'A',
  140. type:'line',
  141. },
  142. {
  143. name:'B',
  144. type:'line',
  145. },
  146. {
  147. name:'C',
  148. type:'line',
  149. }
  150. ]
  151. };
  152. testHelper.create(echarts, 'category-no-encode-two-value-axis', {
  153. title: 'category: no encode declared, two value axis',
  154. option: option,
  155. dataTable: source
  156. });
  157. });
  158. </script>
  159. <script>
  160. require([
  161. 'echarts'
  162. ], function (echarts) {
  163. var source = [
  164. ['周一', 120, '苹果', 150, 320, 820],
  165. ['周二', 132, '狸猫', 232, 332, 932],
  166. ['周三', 101, '周一', 201, 301, 901],
  167. ['周四', 134, '周八', 154, 334, 934],
  168. ['周五', 90, '周六', 190, 309, 1290],
  169. ['周六', 230, '-', 330, 330, 1330],
  170. ['周日', 210, '周日', 410, 320, 1320]
  171. ];
  172. var option = {
  173. legend: {
  174. data:[
  175. '{x: 0, y: 1}',
  176. '{x: 2, y: 3}',
  177. '{x: 2, y: 4}',
  178. '{x: 1, y: 2}',
  179. '{x: 2, y: 0}'
  180. ]
  181. },
  182. tooltip: {trigger: 'axis'},
  183. grid: {
  184. bottom: 70
  185. },
  186. xAxis: [{
  187. type: 'category',
  188. boundaryGap: false
  189. }],
  190. dataZoom: {
  191. type: 'slider'
  192. },
  193. yAxis: [{
  194. type: 'value'
  195. }, {
  196. type: 'category'
  197. }],
  198. dataset: [{
  199. source: source
  200. }, {
  201. source: [
  202. [122, '第二个 dataset', 44],
  203. [56, '周六', 10],
  204. [96, '狸猫', 112]
  205. ]
  206. }],
  207. series: [
  208. {
  209. name:'{x: 0, y: 1}',
  210. type:'line',
  211. encode: {x: 0, y: 1}
  212. },
  213. {
  214. name:'{x: 2, y: 3}',
  215. type:'line',
  216. encode: {x: 2, y: 3}
  217. },
  218. {
  219. name:'{x: 2, y: 4}',
  220. type:'line',
  221. encode: {x: 2, y: 4}
  222. },
  223. {
  224. name:'{x: 1, y: 2}',
  225. type:'line',
  226. encode: {x: 1, y: 2},
  227. datasetIndex: 1
  228. },
  229. {
  230. name: '{x: 2, y: 0}',
  231. type: 'scatter',
  232. yAxisIndex: 1,
  233. symbolSize: function (val) {
  234. return val[5] / 30;
  235. },
  236. encode: {x: 2, y: 0}
  237. }
  238. ]
  239. };
  240. testHelper.create(echarts, 'category-no-axis-data-multi', {
  241. title: 'category: no axis.data, multi category',
  242. dataTable: source,
  243. option: option
  244. });
  245. });
  246. </script>
  247. <script>
  248. require([
  249. 'echarts'
  250. ], function (echarts) {
  251. var source = [
  252. ['周一', 120, 220, 150, 320, 820],
  253. ['周二', 132, 182, 232, 332, 932],
  254. ['周三', 101, 191, 201, 301, 901],
  255. ['周四', 134, 234, 154, 334, 934],
  256. ['周五', 90, 290, 190, 309, 1290],
  257. ['周六', 230, 330, 330, 330, 1330],
  258. ['周日', 210, 310, 410, 320, 1320]
  259. ];
  260. var option = {
  261. legend: {
  262. data:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
  263. },
  264. tooltip: {trigger: 'axis'},
  265. grid: {
  266. left: '3%',
  267. right: '4%',
  268. bottom: '3%',
  269. containLabel: true
  270. },
  271. xAxis: [
  272. {
  273. type: 'category',
  274. boundaryGap: false
  275. }
  276. ],
  277. yAxis: [
  278. {
  279. type: 'value'
  280. }
  281. ],
  282. dataset: {
  283. source: source
  284. },
  285. series: [
  286. {
  287. name:'邮件营销',
  288. type:'line',
  289. stack: '总量',
  290. areaStyle: {normal: {}}
  291. },
  292. {
  293. name:'联盟广告',
  294. type:'line',
  295. stack: '总量',
  296. areaStyle: {normal: {}}
  297. },
  298. {
  299. name:'视频广告',
  300. type:'line',
  301. stack: '总量',
  302. areaStyle: {normal: {}}
  303. },
  304. {
  305. name:'直接访问',
  306. type:'line',
  307. stack: '总量',
  308. areaStyle: {normal: {}}
  309. },
  310. {
  311. name:'搜索引擎',
  312. type:'line',
  313. stack: '总量',
  314. label: {show: true},
  315. areaStyle: {normal: {}}
  316. }
  317. ]
  318. };
  319. testHelper.create(echarts, 'category-no-encode-no-axis-data-single', {
  320. title: 'category: no encode declared, no axis.data, single category',
  321. dataTable: source,
  322. option: option
  323. });
  324. });
  325. </script>
  326. <script>
  327. require([
  328. 'echarts'
  329. ], function (echarts) {
  330. var source = [
  331. ['周一', 120, 220, 150, 320, 820],
  332. ['周二', 132, 182, 232, 332, 932],
  333. ['周三', 101, 191, 201, 301, 901],
  334. ['周四', 134, 234, 154, 334, 934],
  335. ['周五', 90, 290, 190, 309, 1290],
  336. ['周六', 230, 330, 330, 330, 1330],
  337. ['周日', 210, 310, 410, 320, 1320]
  338. ];
  339. var option = {
  340. legend: {
  341. data:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
  342. },
  343. tooltip: {trigger: 'axis'},
  344. grid: {
  345. left: '3%',
  346. right: '4%',
  347. bottom: '3%',
  348. containLabel: true
  349. },
  350. xAxis: [
  351. {
  352. type: 'category',
  353. boundaryGap: false,
  354. data: ['周零', '周一', '周二', '周三', '周四', '周五', '周六', '周日']
  355. }
  356. ],
  357. yAxis: [
  358. {
  359. type: 'value'
  360. }
  361. ],
  362. dataset: {
  363. source: source
  364. },
  365. series: [
  366. {
  367. name:'邮件营销',
  368. type:'line',
  369. stack: '总量',
  370. areaStyle: {normal: {}}
  371. },
  372. {
  373. name:'联盟广告',
  374. type:'line',
  375. stack: '总量',
  376. areaStyle: {normal: {}}
  377. },
  378. {
  379. name:'视频广告',
  380. type:'line',
  381. stack: '总量',
  382. areaStyle: {normal: {}}
  383. },
  384. {
  385. name:'直接访问',
  386. type:'line',
  387. stack: '总量',
  388. areaStyle: {normal: {}}
  389. },
  390. {
  391. name:'搜索引擎',
  392. type:'line',
  393. stack: '总量',
  394. label: {show: true},
  395. areaStyle: {normal: {}}
  396. }
  397. ]
  398. };
  399. testHelper.create(echarts, 'category-no-encode-has-axis-data', {
  400. title: 'category: no encode declared, axis.data given',
  401. dataTable: source,
  402. option: option
  403. });
  404. });
  405. </script>
  406. <script>
  407. require([
  408. 'echarts'
  409. ], function (echarts) {
  410. var source = [
  411. ['周一', 120, 220, 150, 320, 820],
  412. ['周二', 132, 182, 232, 332, 932],
  413. ['周三', 101, 191, 201, 301, 901],
  414. ['周四', 134, 234, 154, 334, 934],
  415. ['周五', 90, 290, 190, 309, 1290],
  416. ['周六', 230, 330, 330, 330, 1330],
  417. ['周日', 210, 310, 410, 320, 1320]
  418. ];
  419. var option = {
  420. tooltip: {
  421. trigger: 'axis',
  422. axisPointer: {
  423. type: 'cross',
  424. label: {
  425. backgroundColor: '#6a7985'
  426. }
  427. }
  428. },
  429. legend: {
  430. data:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
  431. },
  432. toolbox: {
  433. feature: {
  434. saveAsImage: {}
  435. }
  436. },
  437. grid: {
  438. left: '3%',
  439. right: '4%',
  440. bottom: '3%',
  441. containLabel: true
  442. },
  443. xAxis: [
  444. {
  445. type: 'category',
  446. boundaryGap: false
  447. }
  448. ],
  449. yAxis: [
  450. {
  451. type: 'value'
  452. }
  453. ],
  454. dataset: {
  455. source: source
  456. },
  457. series: [
  458. {
  459. name:'邮件营销',
  460. type:'line',
  461. stack: '总量',
  462. areaStyle: {normal: {}},
  463. encode: {x: 0, y: 1}
  464. },
  465. {
  466. name:'联盟广告',
  467. type:'line',
  468. stack: '总量',
  469. areaStyle: {normal: {}},
  470. encode: {x: 0, y: 2}
  471. },
  472. {
  473. name:'视频广告',
  474. type:'line',
  475. stack: '总量',
  476. areaStyle: {normal: {}},
  477. encode: {x: 0, y: 3}
  478. },
  479. {
  480. name:'直接访问',
  481. type:'line',
  482. stack: '总量',
  483. areaStyle: {normal: {}},
  484. encode: {x: 0, y: 4}
  485. },
  486. {
  487. name:'搜索引擎',
  488. type:'line',
  489. stack: '总量',
  490. label: {
  491. normal: {
  492. show: true,
  493. position: 'top'
  494. }
  495. },
  496. areaStyle: {normal: {}},
  497. encode: {x: 0, y: 5}
  498. }
  499. ]
  500. };
  501. testHelper.create(echarts, 'category', {
  502. title: 'category: encode declared',
  503. dataTable: source,
  504. option: option
  505. });
  506. });
  507. </script>
  508. <script>
  509. require([
  510. 'echarts'
  511. ], function (echarts) {
  512. var source = [
  513. ['周一', 120, 220, 150, 320, 820],
  514. ['周二', 132, 182, 232, 332, 932],
  515. ['周三', 101, 191, 201, 301, 901],
  516. ['周四', 134, 234, 154, 334, 934],
  517. ['周五', 90, 290, 190, 309, 1290],
  518. ['周六', 230, 330, 330, 330, 1330],
  519. ['周日', 210, 310, 410, 320, 1320]
  520. ];
  521. var option = {
  522. tooltip: {
  523. },
  524. legend: {
  525. data:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
  526. },
  527. toolbox: {
  528. feature: {
  529. saveAsImage: {}
  530. }
  531. },
  532. grid: {
  533. left: '3%',
  534. right: '4%',
  535. bottom: '3%',
  536. containLabel: true
  537. },
  538. xAxis: {},
  539. yAxis: {},
  540. grid: {
  541. right: 50,
  542. bottom: 70
  543. },
  544. legend: {
  545. left: 'center',
  546. data: ['A Series', 'B Series']
  547. },
  548. dataZoom: [{
  549. xAxisIndex: 0,
  550. type: 'inside'
  551. }, {
  552. yAxisIndex: 0,
  553. type: 'inside'
  554. }, {
  555. xAxisIndex: 0,
  556. type: 'slider'
  557. }, {
  558. yAxisIndex: 0,
  559. type: 'slider'
  560. }],
  561. dataset: {
  562. source: source
  563. },
  564. series: [
  565. {
  566. name:'A Series',
  567. type:'scatter',
  568. areaStyle: {normal: {}},
  569. encode: {x: 2, y: 1}
  570. },
  571. {
  572. name:'B Series',
  573. type:'scatter',
  574. areaStyle: {normal: {}},
  575. encode: {x: 4, y: 1}
  576. }
  577. ]
  578. };
  579. testHelper.create(echarts, 'two-value-axes', {
  580. title: 'two value axes (A: {x: 2, y: 1}, B: {x: 4, y: 1})',
  581. dataTable: source,
  582. option: option
  583. });
  584. });
  585. </script>
  586. <script>
  587. require([
  588. 'echarts'
  589. ], function (echarts) {
  590. var option = {
  591. xAxis: {},
  592. yAxis: {},
  593. series: [
  594. {
  595. type:'line'
  596. }
  597. ]
  598. };
  599. testHelper.create(echarts, 'empty-data', {
  600. title: 'data and dataset undefined, only axis shown.',
  601. option: option
  602. });
  603. });
  604. </script>
  605. <script>
  606. require([
  607. 'echarts'
  608. ], function (echarts) {
  609. var option = {
  610. legend: {},
  611. tooltip: {trigger: 'axis'},
  612. xAxis: {type: 'category'},
  613. yAxis: {},
  614. series: [
  615. {type:'line', encode: {x: 'date', y: 'Matcha Latte', itemId: 'date'}},
  616. {type:'line', encode: {x: 'date', y: 'Milk Tea', itemId: 'date'}},
  617. {type:'line', encode: {x: 'date', y: 'Cheese Cocoa', itemId: 'date'}},
  618. {type:'line', encode: {x: 'date', y: 'Walnut Brownie', itemId: 'date'}}
  619. ]
  620. };
  621. var baseSource = [
  622. ['date', 'Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
  623. ['2012-03-01', 11.1, 40.4, 65.1, 13.3],
  624. ['2012-03-02', 36.5, 52.1, 85.7, 23.1],
  625. ['2012-03-03', 64.1, 17.2, 99.5, 16.4],
  626. ['2012-03-04', 15.2, 77.1, 29.2, 62.4],
  627. ['2012-03-05', 55.4, 73.1, 49.2, 22.9],
  628. ['2012-03-06', 35.2, 27.1, 24.6, 92.7],
  629. ['2012-03-07', 51.7, 57.1, 89.1, 69.2]
  630. ];
  631. var lastDate = +echarts.number.parseDate('2012-03-07');
  632. var chart = testHelper.create(echarts, 'dynamic-category', {
  633. title: 'dynamic-category',
  634. dataTable: keyColumnsDrink,
  635. option: option,
  636. info: baseSource
  637. });
  638. if (chart) {
  639. setInterval(function () {
  640. lastDate += 3600 * 24 * 1000;
  641. baseSource.push([
  642. echarts.format.formatTime('yyyy-MM-dd', lastDate),
  643. +(Math.random() * 100).toFixed(1),
  644. +(Math.random() * 100).toFixed(1),
  645. +(Math.random() * 100).toFixed(1),
  646. +(Math.random() * 100).toFixed(1)
  647. ]);
  648. baseSource.splice(1, 1);
  649. chart.setOption({
  650. dataset: {
  651. source: baseSource
  652. }
  653. });
  654. }, 1000);
  655. }
  656. });
  657. </script>
  658. <script>
  659. require([
  660. 'echarts'
  661. ], function (echarts) {
  662. var option = {
  663. legend: {},
  664. tooltip: {trigger: 'axis'},
  665. xAxis: {type: 'time'},
  666. yAxis: {},
  667. series: [
  668. {type:'line', encode: {x: 'date', y: 'Matcha Latte', itemId: 'date'}},
  669. {type:'line', encode: {x: 'date', y: 'Milk Tea', itemId: 'date'}},
  670. {type:'line', encode: {x: 'date', y: 'Cheese Cocoa', itemId: 'date'}},
  671. {type:'line', encode: {x: 'date', y: 'Walnut Brownie', itemId: 'date'}}
  672. ]
  673. };
  674. var baseSource = [
  675. ['date', 'Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
  676. ['2012-03-01', 11.1, 40.4, 65.1, 13.3],
  677. ['2012-03-02', 36.5, 52.1, 85.7, 23.1],
  678. ['2012-03-03', 64.1, 17.2, 99.5, 16.4],
  679. ['2012-03-04', 15.2, 77.1, 29.2, 62.4],
  680. ['2012-03-05', 55.4, 73.1, 49.2, 22.9],
  681. ['2012-03-06', 35.2, 27.1, 24.6, 92.7],
  682. ['2012-03-07', 51.7, 57.1, 89.1, 69.2]
  683. ];
  684. var lastDate = +echarts.number.parseDate('2012-03-07');
  685. var chart = testHelper.create(echarts, 'dynamic-time', {
  686. title: 'dynamic-time',
  687. dataTable: keyColumnsDrink,
  688. option: option,
  689. info: baseSource
  690. });
  691. if (chart) {
  692. setInterval(function () {
  693. lastDate += 3600 * 24 * 1000;
  694. baseSource.push([
  695. echarts.format.formatTime('yyyy-MM-dd', lastDate),
  696. +(Math.random() * 100).toFixed(1),
  697. +(Math.random() * 100).toFixed(1),
  698. +(Math.random() * 100).toFixed(1),
  699. +(Math.random() * 100).toFixed(1)
  700. ]);
  701. baseSource.splice(1, 1);
  702. chart.setOption({
  703. dataset: {
  704. source: baseSource
  705. }
  706. });
  707. }, 1000);
  708. }
  709. });
  710. </script>
  711. </body>
  712. </html>