pictorial-single.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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. <script src="data/pie-texture.js"></script>
  10. <script src="data/symbols.js"></script>
  11. <meta name="viewport" content="width=device-width, initial-scale=1" />
  12. <link rel="stylesheet" href="lib/reset.css">
  13. </head>
  14. <body>
  15. <style>
  16. body {
  17. }
  18. .chart {
  19. position: relative;
  20. height: 500px;
  21. max-width: 1000px;
  22. margin: 0 auto;
  23. }
  24. h2 {
  25. text-align: center;
  26. font-size: 16px;
  27. line-height: 30px;
  28. font-weight: normal;
  29. background: #dde;
  30. margin: 0;
  31. }
  32. strong {
  33. color: #971f3c;
  34. }
  35. </style>
  36. <h2>repeatDirection | dynamic</h2>
  37. <div class="chart" id="paper-and-hill"></div>
  38. <h2>texture</h2>
  39. <div class="chart" id="texture"></div>
  40. <h2>horizontal | no clip | symbolOffset</h2>
  41. <div class="chart" id="velocity"></div>
  42. <h2>clip</h2>
  43. <div class="chart" id="clip"></div>
  44. <h2>dotted | gradient</h2>
  45. <div class="chart" id="dotted"></div>
  46. <script>
  47. function makeChart(id, option, cb) {
  48. require([
  49. 'echarts'
  50. // 'echarts/chart/pictorialBar',
  51. // 'echarts/chart/bar',
  52. // 'echarts/chart/line',
  53. // 'echarts/chart/scatter',
  54. // 'echarts/component/grid',
  55. // 'echarts/component/legend',
  56. // 'echarts/component/markLine',
  57. // 'echarts/component/tooltip',
  58. // 'echarts/component/dataZoom'
  59. ], function (echarts) {
  60. if (typeof option === 'function') {
  61. option = option(echarts);
  62. }
  63. var main = document.getElementById(id);
  64. if (main) {
  65. var chartMain = document.createElement('div');
  66. chartMain.style.cssText = 'height:100%';
  67. main.appendChild(chartMain);
  68. var chart = echarts.init(chartMain);
  69. chart.setOption(option);
  70. window.addEventListener('resize', chart.resize);
  71. cb && cb(echarts, chart);
  72. }
  73. });
  74. }
  75. </script>
  76. <script>
  77. makeChart('paper-and-hill', {
  78. backgroundColor: '#0f375f',
  79. tooltip: {},
  80. legend: {
  81. data: ['all'],
  82. textStyle: {color: '#ddd'}
  83. },
  84. xAxis: [{
  85. data: ['圣诞节儿童愿望清单', '', '珠穆朗玛', '乞力马扎罗'],
  86. axisTick: {show: false},
  87. axisLine: {show: false},
  88. axisLabel: {
  89. margin: 20,
  90. textStyle: {
  91. color: '#ddd',
  92. fontSize: 14
  93. }
  94. }
  95. }],
  96. yAxis: {
  97. splitLine: {show: false},
  98. axisTick: {show: false},
  99. axisLine: {show: false},
  100. axisLabel: {show: false}
  101. },
  102. markLine: {
  103. z: -1
  104. },
  105. animationEasing: 'elasticOut',
  106. series: [{
  107. type: 'pictorialBar',
  108. name: 'all',
  109. hoverAnimation: true,
  110. label: {
  111. normal: {
  112. show: true,
  113. position: 'top',
  114. formatter: '{c} m',
  115. textStyle: {
  116. fontSize: 16,
  117. color: '#e54035'
  118. }
  119. }
  120. },
  121. data: [{
  122. value: 13000,
  123. symbol: imageSymbols.paper,
  124. symbolRepeat: true,
  125. symbolSize: ['130%', '20%'],
  126. symbolOffset: [0, 10],
  127. symbolMargin: '-30%',
  128. animationDelay: function (dataIndex, params) {
  129. return params.index * 30;
  130. }
  131. }, {
  132. value: '-',
  133. symbol: 'none',
  134. }, {
  135. value: 8844,
  136. symbol: 'image://./data/hill-Qomolangma.png',
  137. symbolSize: ['200%', '105%'],
  138. symbolPosition: 'end',
  139. z: 10
  140. }, {
  141. value: 5895,
  142. symbol: 'image://./data/hill-Kilimanjaro.png',
  143. symbolSize: ['200%', '105%'],
  144. symbolPosition: 'end'
  145. }],
  146. markLine: {
  147. symbol: ['none', 'none'],
  148. label: {
  149. normal: {show: false}
  150. },
  151. lineStyle: {
  152. normal: {
  153. color: '#e54035',
  154. width: 2
  155. }
  156. },
  157. data: [{
  158. yAxis: 8844
  159. }]
  160. }
  161. }, {
  162. name: 'all',
  163. type: 'pictorialBar',
  164. symbol: 'circle',
  165. itemStyle: {
  166. normal: {
  167. color: '#185491'
  168. }
  169. },
  170. silent: true,
  171. symbolOffset: [0, '50%'],
  172. z: -10,
  173. data: [{
  174. value: 1,
  175. symbolSize: ['150%', 50]
  176. }, {
  177. value: '-'
  178. }, {
  179. value: 1,
  180. symbolSize: ['200%', 50]
  181. }, {
  182. value: 1,
  183. symbolSize: ['200%', 50]
  184. }]
  185. }]
  186. });
  187. </script>
  188. <script>
  189. var img = new Image();
  190. img.src = window.pieTexture;
  191. makeChart('texture', {
  192. backgroundColor: '#13978b',
  193. tooltip: {},
  194. xAxis: {
  195. data: ['a', 'b', 'c'],
  196. axisTick: {show: false}
  197. },
  198. yAxis: {
  199. splitLine: {show: false},
  200. axisTick: {show: false}
  201. },
  202. animationEasing: 'elasticOut',
  203. series: [{
  204. name: 'all',
  205. type: 'pictorialBar',
  206. barCategoryGap: '40%',
  207. label: {
  208. normal: {
  209. show: true,
  210. position: 'top',
  211. textStyle: {
  212. color: '#e54035'
  213. }
  214. }
  215. },
  216. hoverAnimation: true,
  217. data: [{
  218. value: 8844,
  219. symbol: 'circle',
  220. label: {
  221. normal: {formatter: 'symbolPatternSize: default'}
  222. },
  223. itemStyle: {
  224. normal: {
  225. color: {
  226. image: img,
  227. repeat: 'repeat'
  228. }
  229. }
  230. }
  231. }, {
  232. value: 8844,
  233. symbol: 'path://M0,10 L10,10 L5,0 L0,10 z',
  234. label: {
  235. normal: {formatter: 'symbolPatternSize: 800'}
  236. },
  237. symbolPatternSize: 800,
  238. itemStyle: {
  239. normal: {
  240. color: {
  241. image: img,
  242. repeat: 'repeat'
  243. }
  244. }
  245. }
  246. }, {
  247. value: 8844,
  248. symbol: 'path://M0,10 L10,10 L5,0 L0,10 z',
  249. label: {
  250. normal: {formatter: 'symbolPatternSize: 50'}
  251. },
  252. symbolPatternSize: 50,
  253. itemStyle: {
  254. normal: {
  255. color: {
  256. image: img,
  257. repeat: 'repeat'
  258. }
  259. }
  260. }
  261. }]
  262. }]
  263. });
  264. </script>
  265. <script>
  266. var rawData = [
  267. {name: '驯鹿', velocity: 123, symbol: 'reindeer'},
  268. {name: '火箭', velocity: 60, symbol: 'rocket'},
  269. {name: '飞机', velocity: 25, symbol: 'plane'},
  270. {name: '高铁', velocity: 18, symbol: 'train'},
  271. {name: '轮船', velocity: 12, symbol: 'ship'},
  272. {name: '汽车', velocity: 9, symbol: 'car'},
  273. {name: '跑步', velocity: 2, symbol: 'run'},
  274. {name: '步行', velocity: 1, symbol: 'walk'}
  275. ];
  276. // 真实数据:
  277. // {name: '驯鹿', velocity: 4705882, symbol: 'reindeer'},
  278. // {name: '火箭', velocity: 38880, symbol: 'thunder'},
  279. // {name: '飞机', velocity: 1028, symbol: 'plane'},
  280. // {name: '高铁', velocity: 300, symbol: 'train'},
  281. // {name: '汽车', velocity: 60, symbol: 'car'},
  282. // {name: '轮船', velocity: 30, symbol: 'ship'},
  283. // {name: '跑步', velocity: 15, symbol: 'run'},
  284. // {name: '步行', velocity: 5, symbol: 'walk'}
  285. makeChart('velocity', {
  286. tooltip: {
  287. trigger: 'axis',
  288. axisPointer: {
  289. type: 'none'
  290. }
  291. },
  292. xAxis: {
  293. data: rawData.map(function (item) {
  294. return item.name;
  295. }),
  296. axisTick: {show: false},
  297. axisLine: {show: false},
  298. axisLabel: {
  299. textStyle: {
  300. color: '#e54035'
  301. }
  302. }
  303. },
  304. yAxis: {
  305. splitLine: {show: false},
  306. axisTick: {show: false},
  307. axisLine: {show: false},
  308. axisLabel: {show: false}
  309. },
  310. color: ['#e54035'],
  311. series: [{
  312. name: 'hill',
  313. type: 'pictorialBar',
  314. barCategoryGap: '-50%',
  315. symbol: 'path://M0,10 L10,10 L5,0 L0,10 z',
  316. itemStyle: {
  317. normal: {
  318. opacity: 0.5
  319. },
  320. emphasis: {
  321. opacity: 1
  322. }
  323. },
  324. data: rawData.map(function (item) {
  325. return item.velocity;
  326. }),
  327. z: 10
  328. }, {
  329. name: 'glyph',
  330. type: 'pictorialBar',
  331. symbolPosition: 'end',
  332. symbolSize: [25, 25],
  333. symbolOffset: [0, -35],
  334. itemStyle: {
  335. emphasis: {
  336. color: 'green'
  337. }
  338. },
  339. data: rawData.map(function (item) {
  340. return {
  341. value: item.velocity,
  342. symbol: pathSymbols[item.symbol]
  343. };
  344. })
  345. }]
  346. });
  347. </script>
  348. <script>
  349. function getBodyImage(index) {
  350. return pathSymbols['body' + index];
  351. }
  352. var bodyMax = 150;
  353. makeChart('clip', {
  354. tooltip: {
  355. },
  356. legend: {
  357. data: ['typeA', 'typeB'],
  358. selectedMode: 'single'
  359. },
  360. xAxis: {
  361. data: ['a', 'b', 'c', 'd', 'e'],
  362. axisTick: {show: false},
  363. axisLine: {show: false},
  364. axisLabel: {
  365. textStyle: {
  366. color: '#e54035'
  367. }
  368. }
  369. },
  370. yAxis: {
  371. max: bodyMax,
  372. splitLine: {show: false}
  373. },
  374. grid: {
  375. left: 'center',
  376. top: 100,
  377. width: 800,
  378. height: 230
  379. },
  380. series: [{
  381. name: 'typeA',
  382. type: 'pictorialBar',
  383. symbolClip: true,
  384. symbolBoundingData: bodyMax,
  385. data: [{
  386. value: 123,
  387. symbol: getBodyImage(0)
  388. }, {
  389. value: 34,
  390. symbol: getBodyImage(1)
  391. }, {
  392. value: 101,
  393. symbol: getBodyImage(2)
  394. }, {
  395. value: 89,
  396. symbol: getBodyImage(3)
  397. }, {
  398. value: 72,
  399. symbol: getBodyImage(4)
  400. }],
  401. z: 10
  402. }, {
  403. name: 'typeB',
  404. type: 'pictorialBar',
  405. symbolClip: true,
  406. symbolBoundingData: bodyMax,
  407. data: [{
  408. value: 12,
  409. symbol: getBodyImage(0)
  410. }, {
  411. value: 44,
  412. symbol: getBodyImage(1)
  413. }, {
  414. value: 131,
  415. symbol: getBodyImage(2)
  416. }, {
  417. value: 33,
  418. symbol: getBodyImage(3)
  419. }, {
  420. value: 142,
  421. symbol: getBodyImage(4)
  422. }],
  423. z: 10
  424. }, {
  425. name: 'full',
  426. type: 'pictorialBar',
  427. symbolBoundingData: bodyMax,
  428. itemStyle: {
  429. normal: {
  430. color: '#ccc'
  431. }
  432. },
  433. data: [{
  434. value: 1,
  435. symbol: getBodyImage(0)
  436. }, {
  437. value: 1,
  438. symbol: getBodyImage(1)
  439. }, {
  440. value: 1,
  441. symbol: getBodyImage(2)
  442. }, {
  443. value: 1,
  444. symbol: getBodyImage(3)
  445. }, {
  446. value: 1,
  447. symbol: getBodyImage(4)
  448. }]
  449. }]
  450. });
  451. </script>
  452. <script>
  453. makeChart('dotted', function (echarts) {
  454. var bgColor = '#0f375f';
  455. var category = [];
  456. var count = 20;
  457. var dottedBase = +new Date();
  458. var lineData = [];
  459. var barData = [];
  460. for (var i = 0; i < count; i++) {
  461. var date = new Date(dottedBase + 3600 * 24);
  462. category.push([
  463. date.getFullYear(),
  464. date.getMonth() + 1,
  465. date.getDate()
  466. ].join('-'));
  467. var b = Math.random() * 200;
  468. var d = Math.random() * 200;
  469. barData.push(b)
  470. lineData.push(d + b);
  471. }
  472. return {
  473. backgroundColor: bgColor,
  474. tooltip: {
  475. },
  476. legend: {
  477. data: ['line', 'bar'],
  478. textStyle: {
  479. color: '#ccc'
  480. }
  481. },
  482. xAxis: {
  483. data: category,
  484. axisLine: {
  485. lineStyle: {
  486. color: '#ccc'
  487. }
  488. }
  489. },
  490. yAxis: {
  491. splitLine: {show: false},
  492. axisLine: {
  493. lineStyle: {
  494. color: '#ccc'
  495. }
  496. }
  497. },
  498. series: [{
  499. name: 'line',
  500. type: 'line',
  501. smooth: true,
  502. showAllSymbol: true,
  503. symbol: 'emptyCircle',
  504. symbolSize: 15,
  505. data: lineData
  506. }, {
  507. name: 'bar',
  508. type: 'bar',
  509. barWidth: 10,
  510. itemStyle: {
  511. normal: {
  512. barBorderRadius: 5,
  513. color: {
  514. type: 'linear',
  515. x: 0,
  516. y: 0,
  517. x2: 0,
  518. y2: 1,
  519. colorStops: [
  520. {offset: 0, color: '#14c8d4'},
  521. {offset: 1, color: '#43eec6'}
  522. ]
  523. }
  524. }
  525. },
  526. data: barData
  527. }, {
  528. name: 'line',
  529. type: 'bar',
  530. barWidth: 10,
  531. barGap: '-100%',
  532. itemStyle: {
  533. normal: {
  534. color: new echarts.graphic.LinearGradient(
  535. 0, 0, 0, 1,
  536. [
  537. {offset: 0, color: 'rgba(20,200,212,0.5)'},
  538. {offset: 0.2, color: 'rgba(20,200,212,0.2)'},
  539. {offset: 1, color: 'rgba(20,200,212,0)'}
  540. ]
  541. )
  542. }
  543. },
  544. z: -12,
  545. data: lineData
  546. }, {
  547. name: 'dotted',
  548. type: 'pictorialBar',
  549. symbol: 'rect',
  550. itemStyle: {
  551. normal: {
  552. color: bgColor
  553. }
  554. },
  555. symbolRepeat: true,
  556. symbolSize: [12, 4],
  557. symbolMargin: 1,
  558. z: -10,
  559. data: lineData
  560. }]
  561. };
  562. });
  563. </script>
  564. </body>
  565. </html>