axes.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <link rel="stylesheet" href="reset.css">
  7. </head>
  8. <body>
  9. <style>
  10. #main {
  11. position: relative;
  12. min-width: 1080px; /* 4 columns */
  13. text-align: center;
  14. }
  15. .title {
  16. display: block;
  17. cursor: pointer;
  18. text-decoration: none;
  19. clear: both;
  20. text-align: center;
  21. margin: 0;
  22. background: #eef;
  23. line-height: 22px;
  24. }
  25. .block {
  26. display: inline-block;
  27. *display: inline;
  28. *zoom: 1;
  29. vertical-align: top;
  30. margin: 30px 0 30px 50px;
  31. }
  32. .block .ec {
  33. width: 200px;
  34. height: 200px;
  35. }
  36. .block label {
  37. width: 200px;
  38. display: block;
  39. text-align: center;
  40. background: #eee;
  41. border-radius: 3px;
  42. font-size: 12px;
  43. line-height: 18px;
  44. padding: 0 5px;
  45. }
  46. </style>
  47. <div id="main"></div>
  48. <script>
  49. var echarts;
  50. var zrUtil;
  51. require([
  52. 'echarts',
  53. 'zrender/core/util',
  54. 'echarts/chart/line',
  55. 'echarts/chart/bar',
  56. 'echarts/chart/parallel',
  57. 'echarts/component/legend',
  58. 'echarts/component/grid',
  59. 'echarts/component/polar',
  60. 'echarts/component/parallel',
  61. 'echarts/component/tooltip'
  62. ], function (ec, zu) {
  63. echarts = ec;
  64. zrUtil = zu;
  65. var makeCartesian = zrUtil.curry(makeChart, defaultCartesianOption);
  66. var makeCategoryOnY = zrUtil.curry(makeChart, categoryOnYOption);
  67. var makePolar = zrUtil.curry(makeChart, defaultPolarOption);
  68. console.profile('render');
  69. renderTitle('cartesian normal');
  70. // inverse
  71. makeCartesian('x: forward, y: forward', {
  72. xAxis: {},
  73. yAxis: {}
  74. });
  75. makeCartesian('x: inverse, y: inverse', {
  76. xAxis: {inverse: true},
  77. yAxis: {inverse: true}
  78. });
  79. makeCartesian('x: forward, y: inverse', {
  80. xAxis: {},
  81. yAxis: {inverse: true}
  82. });
  83. makeCartesian('x: inverse, y: forward', {
  84. xAxis: {inverse: true},
  85. yAxis: {}
  86. });
  87. renderTitle('cartesian min max and onZero');
  88. makeCartesian('xAxis.axisLine.onZero: false, yAxis.min: 0.4, yAxis.max: 0.8', {
  89. xAxis: {axisLine: {onZero: false}},
  90. yAxis: {min: 0.4, max: 0.8}
  91. });
  92. makeCartesian('xAxis.axisLine.onZero: false, yAxis.min: -5, yAxis.max: 1.8', {
  93. xAxis: {axisLine: {onZero: false}},
  94. yAxis: {min: -5, max: 1.8}
  95. });
  96. makeCartesian('xAxis.axisLine.onZero: false, yAxis.min: -5', {
  97. xAxis: {axisLine: {onZero: false}},
  98. yAxis: {min: -5}
  99. });
  100. makeCartesian('xAxis.axisLine.onZero: false, yAxis.max: 0.8', {
  101. xAxis: {axisLine: {onZero: false}},
  102. yAxis: {max: 0.8}
  103. });
  104. makeCartesian('(zero outside) xAxis.axisLine.onZero: true, yAxis.min: 0.4, yAxis.max: 0.8', {
  105. xAxis: {axisLine: {onZero: true}},
  106. yAxis: {min: 0.4, max: 0.8}
  107. });
  108. makeCartesian('(zero near top) xAxis.axisLine.onZero: true, yAxis.min: -5, yAxis.max: 1.8', {
  109. xAxis: {axisLine: {onZero: true}},
  110. yAxis: {min: -5, max: 1.8}
  111. });
  112. makeCartesian('(zero near bottom) xAxis.axisLine.onZero: true, yAxis.min: -1, yAxis.max: 10', {
  113. xAxis: {axisLine: {onZero: true}},
  114. yAxis: {min: -1, max: 10}
  115. });
  116. makeCategoryOnY('(zero near left) yAxis.axisLine.onZero: true, xAxis.min: -1, xAxis.max: 10', {
  117. xAxis: {min: -1, max: 10},
  118. yAxis: {axisLine: {onZero: true}},
  119. });
  120. makeCategoryOnY('(zero near right) yAxis.axisLine.onZero: true, xAxis.min: -5, xAxis.max: 1.8', {
  121. xAxis: {min: -5, max: 1.8},
  122. yAxis: {axisLine: {onZero: true}},
  123. });
  124. makeCategoryOnY('(zero right) yAxis.axisLine.onZero: true, xAxis.min: -5, xAxis.max: 1.8, yAxis.position: right', {
  125. xAxis: {min: -5, max: 1.8},
  126. yAxis: {axisLine: {onZero: true}, position: 'right'},
  127. });
  128. makeCartesian('(zero top) xAxis.axisLine.onZero: true, yAxis.min: -1, yAxis.max: 1, xAxis.position: top', {
  129. xAxis: {axisLine: {onZero: true}, position: 'top'},
  130. yAxis: {min: -1, max: 1}
  131. });
  132. renderTitle('cartesian category on y');
  133. makeCategoryOnY('x: forward, y: forward', {
  134. xAxis: {},
  135. yAxis: {}
  136. });
  137. makeCategoryOnY('x: inverse, y: inverse', {
  138. xAxis: {inverse: true},
  139. yAxis: {inverse: true}
  140. });
  141. makeCategoryOnY('x: forward, y: inverse', {
  142. xAxis: {},
  143. yAxis: {inverse: true}
  144. });
  145. makeCategoryOnY('x: inverse, y: forward', {
  146. xAxis: {inverse: true},
  147. yAxis: {}
  148. });
  149. renderTitle('cartesian position setting');
  150. // position
  151. makeCartesian('x: forward top, y: forward right', {
  152. xAxis: {position: 'top'},
  153. yAxis: {position: 'right'}
  154. });
  155. makeCartesian('x: inverse bottom, y: inverse right', {
  156. xAxis: {inverse: true, position: 'bottom'},
  157. yAxis: {inverse: true, position: 'right'}
  158. });
  159. makeCartesian('x: forward bottom, y: inverse right', {
  160. xAxis: {position: 'bottom'},
  161. yAxis: {inverse: true, position: 'right'}
  162. });
  163. makeCartesian('x: inverse top, y: forward right', {
  164. xAxis: {inverse: true, position: 'top'},
  165. yAxis: {position: 'right'}
  166. });
  167. renderTitle('cartesian tick or label inside');
  168. makeCartesian('yAxis.axisTick: inside', {
  169. xAxis: {},
  170. yAxis: {axisTick: {inside: true}}
  171. });
  172. makeCartesian('yAxis.axisLabel: inside, yAxis.axisTick: inside', {
  173. xAxis: {},
  174. yAxis: {axisLabel: {inside: true}, axisTick: {inside: true}}
  175. });
  176. makeCartesian('xAxis.axisTick: inside', {
  177. xAxis: {axisTick: {inside: true}},
  178. yAxis: {}
  179. });
  180. makeCartesian('xAxis.axisLabel: inside', {
  181. xAxis: {axisLabel: {inside: true}},
  182. yAxis: {}
  183. });
  184. makeCartesian('xAxis.axisLabel: inside, top, xAxisLine.onZero: false', {
  185. xAxis: {axisLabel: {inside: true}, position: 'top', axisLine: {onZero: false}},
  186. yAxis: {}
  187. });
  188. renderTitle('cartesian name location');
  189. // name location
  190. makeCartesian('x: forward start, y: forward start', {
  191. xAxis: {nameLocation: 'start'},
  192. yAxis: {nameLocation: 'start'}
  193. });
  194. makeCartesian('x: inverse start, y: inverse start', {
  195. xAxis: {inverse: true, nameLocation: 'start'},
  196. yAxis: {inverse: true, nameLocation: 'start'}
  197. });
  198. makeCartesian('x: forward start, y: inverse start', {
  199. xAxis: {nameLocation: 'start'},
  200. yAxis: {inverse: true, nameLocation: 'start'}
  201. });
  202. makeCartesian('x: inverse start, y: forward start', {
  203. xAxis: {inverse: true, nameLocation: 'start'},
  204. yAxis: {nameLocation: 'start'}
  205. });
  206. makeCartesian('x: forward middle, y: forward middle', {
  207. xAxis: {nameLocation: 'middle', nameGap: 30},
  208. yAxis: {nameLocation: 'middle', nameGap: 30}
  209. });
  210. makeCartesian('x: forward middle, y: forward middle right', {
  211. xAxis: {nameLocation: 'middle', nameGap: 30},
  212. yAxis: {nameLocation: 'middle', nameGap: 30, position: 'right'}
  213. });
  214. makeCartesian('x: inverse middle, y: inverse middle', {
  215. xAxis: {inverse: true, nameLocation: 'middle', nameGap: 30},
  216. yAxis: {inverse: true, nameLocation: 'middle', nameGap: 30}
  217. });
  218. makeCartesian('x: inverse middle top, y: inverse middle', {
  219. xAxis: {inverse: true, nameLocation: 'middle', nameGap: 30, position: 'top'},
  220. yAxis: {inverse: true, nameLocation: 'middle', nameGap: 30}
  221. });
  222. renderTitle('polar normal');
  223. // inverse
  224. makePolar('angle: forward, radius: forward', {
  225. angleAxis: {},
  226. radiusAxis: {}
  227. });
  228. makePolar('angle: inverse, radius: inverse', {
  229. angleAxis: {inverse: true},
  230. radiusAxis: {inverse: true}
  231. });
  232. makePolar('angle: forward, radius: inverse', {
  233. angleAxis: {},
  234. radiusAxis: {inverse: true}
  235. });
  236. makePolar('angle: inverse, radius: forward', {
  237. angleAxis: {inverse: true},
  238. radiusAxis: {}
  239. });
  240. renderTitle('polar angle settting');
  241. // startAngle
  242. makePolar('angle: forward startAngle23, radius: forward', {
  243. angleAxis: {startAngle: 23},
  244. radiusAxis: {}
  245. });
  246. makePolar('angle: forward startAngle64, radius: forward', {
  247. angleAxis: {startAngle: 64},
  248. radiusAxis: {}
  249. });
  250. makePolar('angle: forward startAngle90, radius: forward', {
  251. angleAxis: {startAngle: 90},
  252. radiusAxis: {}
  253. });
  254. makePolar('angle: forward startAngle108, radius: forward', {
  255. angleAxis: {startAngle: 108},
  256. radiusAxis: {}
  257. });
  258. makePolar('angle: forward startAngle164, radius: forward', {
  259. angleAxis: {startAngle: 164},
  260. radiusAxis: {}
  261. });
  262. makePolar('angle: forward startAngle180, radius: forward', {
  263. angleAxis: {startAngle: 180},
  264. radiusAxis: {}
  265. });
  266. makePolar('angle: forward startAngle204, radius: forward', {
  267. angleAxis: {startAngle: 204},
  268. radiusAxis: {}
  269. });
  270. makePolar('angle: forward startAngle250, radius: forward', {
  271. angleAxis: {startAngle: 250},
  272. radiusAxis: {}
  273. });
  274. makePolar('angle: forward startAngle270, radius: forward', {
  275. angleAxis: {startAngle: 270},
  276. radiusAxis: {}
  277. });
  278. makePolar('angle: forward startAngle270, radius: forward', {
  279. angleAxis: {startAngle: 270},
  280. radiusAxis: {}
  281. });
  282. makePolar('angle: forward startAngle294, radius: forward', {
  283. angleAxis: {startAngle: 294},
  284. radiusAxis: {}
  285. });
  286. makePolar('angle: forward startAngle344, radius: forward', {
  287. angleAxis: {startAngle: 344},
  288. radiusAxis: {}
  289. });
  290. makePolar('angle: forward startAngle360, radius: forward', {
  291. angleAxis: {startAngle: 360},
  292. radiusAxis: {}
  293. });
  294. renderTitle('polar min max');
  295. makePolar('radiusAxis.min: 1, radiusAxis.max: 3', {
  296. angleAxis: {},
  297. radiusAxis: {min: 1, max: 9}
  298. });
  299. makePolar('radiusAxis.min: -1', {
  300. angleAxis: {},
  301. radiusAxis: {min: -1}
  302. });
  303. renderTitle('polar clockwise');
  304. makePolar('clockwise: true', {
  305. angleAxis: {clockwise: true},
  306. radiusAxis: {}
  307. });
  308. makePolar('clockwise: false', {
  309. angleAxis: {clockwise: false},
  310. radiusAxis: {}
  311. });
  312. renderTitle('polar inverse angle settting');
  313. // startAngle
  314. makePolar('angle: inverse startAngle23, radius: forward', {
  315. angleAxis: {inverse: true, startAngle: 23},
  316. radiusAxis: {}
  317. });
  318. makePolar('angle: forward startAngle23, radius: inverse', {
  319. angleAxis: {startAngle: 23},
  320. radiusAxis: {inverse: true}
  321. });
  322. renderTitle('parallel');
  323. var makeParallel = zrUtil.curry(makeChart, defaultParallelOption);
  324. makeParallel('layout: horizontal', {
  325. });
  326. makeParallel('layout: horizontal, axis2 forward start', {
  327. parallelAxis: makeParallelAxisOption({nameLocation: 'start'})
  328. });
  329. makeParallel('layout: horizontal, axis2 inverse start', {
  330. parallelAxis: makeParallelAxisOption({inverse: true, nameLocation: 'start'})
  331. });
  332. makeParallel('layout: vertical', {
  333. });
  334. makeParallel('layout: vertical, axis2 forward start', {
  335. parallel: {layout: 'vertical'},
  336. parallelAxis: makeParallelAxisOption({nameLocation: 'start'})
  337. });
  338. makeParallel('layout: vertical, axis2 inverse start', {
  339. parallel: {layout: 'vertical'},
  340. parallelAxis: makeParallelAxisOption({inverse: true, nameLocation: 'start'})
  341. });
  342. console.profileEnd('render');
  343. });
  344. function makeParallelAxisOption(secondOpt) {
  345. return [
  346. {dim: 0, name: '维度1'},
  347. zrUtil.merge({dim: 'dim1', name: '维度2'}, secondOpt, true),
  348. {dim: 2, name: '维度3'},
  349. {dim: 3, name: '维度4'}
  350. ];
  351. }
  352. function renderTitle(label) {
  353. var containerEl = document.getElementById('main');
  354. var el = document.createElement('a');
  355. el.className = 'title';
  356. var html = encodeHTML(label);
  357. el.innerHTML = html;
  358. el.href = '#' + html.replace(/\s/g, '_');
  359. el.name = html.replace(/\s/g, '_');
  360. containerEl.appendChild(el);
  361. }
  362. function makeChart(getOption, label, opt) {
  363. opt = opt || {};
  364. var containerEl = document.getElementById('main');
  365. var el = document.createElement('div');
  366. el.className = 'block';
  367. el.innerHTML = '<div class="ec"></div><label>' + encodeHTML(label) + '</label>';
  368. containerEl.appendChild(el);
  369. var chart = echarts.init(el.firstChild, null, {renderer: 'canvas'});
  370. chart.setOption(zrUtil.merge(opt, getOption()));
  371. }
  372. function defaultCartesianOption() {
  373. var xAxisData = [];
  374. var data1 = [];
  375. for (var i = 0; i < 30; i++) {
  376. xAxisData.push('类目' + i);
  377. data1.push(+(Math.random() + 0.5).toFixed(3));
  378. }
  379. return {
  380. legend: {
  381. data: ['line', 'line2', 'line3']
  382. },
  383. tooltip: {
  384. trigger: 'axis',
  385. axisPointer: {type: 'line'}
  386. },
  387. grid: {x: 50, y: 50, x2: 50, y2: 50},
  388. xAxis: {
  389. data: xAxisData,
  390. name: 'XName',
  391. boundaryGap: false,
  392. splitArea: {show: false},
  393. splitLine: {show: false}
  394. },
  395. yAxis: {
  396. name: 'YName',
  397. splitArea: {show: true}
  398. },
  399. series: [{
  400. name: 'line',
  401. type: 'line',
  402. stack: 'all',
  403. symbol: 'circle',
  404. symbolSize: 10,
  405. data: data1,
  406. itemStyle: {
  407. normal: {
  408. borderColor: 'white',
  409. borderWidth: 3,
  410. lineStyle: {width: 1}
  411. }
  412. }
  413. }]
  414. };
  415. }
  416. function categoryOnYOption() {
  417. var axisData = [];
  418. var data1 = [];
  419. for (var i = 0; i < 30; i++) {
  420. axisData.push('类目' + i);
  421. data1.push(+(Math.random() + 0.5).toFixed(3));
  422. }
  423. return {
  424. legend: {
  425. data: ['line', 'line2', 'line3']
  426. },
  427. tooltip: {
  428. trigger: 'axis',
  429. axisPointer: {type: 'line'}
  430. },
  431. grid: {x: 50, y: 50, x2: 50, y2: 50},
  432. yAxis: {
  433. data: axisData,
  434. type: 'category',
  435. name: 'YName',
  436. boundaryGap: false,
  437. splitArea: {show: false},
  438. splitLine: {show: false}
  439. },
  440. xAxis: {
  441. type: 'value',
  442. name: 'XName',
  443. splitArea: {show: true}
  444. },
  445. series: [{
  446. name: 'line',
  447. type: 'line',
  448. stack: 'all',
  449. symbol: 'circle',
  450. symbolSize: 10,
  451. data: data1,
  452. itemStyle: {
  453. normal: {
  454. borderColor: 'white',
  455. borderWidth: 3,
  456. lineStyle: {width: 1}
  457. }
  458. }
  459. }]
  460. };
  461. }
  462. function defaultPolarOption() {
  463. var xAxisData = [];
  464. var data1 = [];
  465. for (var i = 0; i < 8; i++) {
  466. xAxisData.push('类目' + i);
  467. data1.push((Math.random() * 2 + 1).toFixed(3));
  468. }
  469. return {
  470. legend: {
  471. data: ['line', 'line2', 'line3']
  472. },
  473. tooltip: {
  474. trigger: 'axis',
  475. axisPointer: {type: 'shadow'}
  476. },
  477. polar: {radius: '65%'},
  478. angleAxis: {data: xAxisData},
  479. radiusAxis: {splitNumber: 4, name: 'radiusName'},
  480. series: [{
  481. coordinateSystem: 'polar',
  482. name: 'line',
  483. stack: 'all',
  484. type: 'line',
  485. symbolSize: 10,
  486. itemStyle: {normal: {areaStyle: {}}},
  487. data: data1
  488. }]
  489. };
  490. }
  491. function defaultParallelOption() {
  492. var dataBJ = [];
  493. for (var i = 0; i < 10; i++) {
  494. var item = [];
  495. for (var j = 0; j < 4; j++) {
  496. item.push(Math.random() * 10);
  497. }
  498. dataBJ.push(item);
  499. }
  500. return {
  501. color: [
  502. '#dd4444', '#fec42c', '#80F1BE'
  503. ],
  504. parallelAxis: makeParallelAxisOption(),
  505. parallel: {
  506. left: 40,
  507. top: 40,
  508. right: 40,
  509. bottom: 40,
  510. parallelAxisDefault: {
  511. type: 'value'
  512. }
  513. },
  514. series: [
  515. {
  516. name: '北京',
  517. type: 'parallel',
  518. data: dataBJ
  519. }
  520. ]
  521. };
  522. }
  523. function encodeHTML(source) {
  524. return source == null
  525. ? ''
  526. : String(source)
  527. .replace(/&/g, '&amp;')
  528. .replace(/</g, '&lt;')
  529. .replace(/>/g, '&gt;')
  530. .replace(/"/g, '&quot;')
  531. .replace(/'/g, '&#39;');
  532. };
  533. </script>
  534. </body>
  535. </html>