echart-pie-doghnut.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. $(function() {
  2. "use strict";
  3. // ------------------------------
  4. // Basic pie chart
  5. // ------------------------------
  6. // based on prepared DOM, initialize echarts instance
  7. var basicpieChart = echarts.init(document.getElementById('basic-pie'));
  8. var option = {
  9. // Add title
  10. title: {
  11. text: 'A site user access source',
  12. subtext: 'Purely Fictitious',
  13. x: 'center'
  14. },
  15. // Add tooltip
  16. tooltip: {
  17. trigger: 'item',
  18. formatter: "{a} <br/>{b}: {c} ({d}%)"
  19. },
  20. // Add legend
  21. legend: {
  22. orient: 'vertical',
  23. x: 'left',
  24. data: ['Direct Access', 'Mail Marketing', 'Union ad', 'Video ad', 'Search Engine']
  25. },
  26. // Add custom colors
  27. color: ['#689f38', '#38649f', '#389f99', '#ee1044', '#ff8f00'],
  28. // Display toolbox
  29. toolbox: {
  30. show: true,
  31. orient: 'vertical',
  32. feature: {
  33. mark: {
  34. show: true,
  35. title: {
  36. mark: 'Markline switch',
  37. markUndo: 'Undo markline',
  38. markClear: 'Clear markline'
  39. }
  40. },
  41. dataView: {
  42. show: true,
  43. readOnly: false,
  44. title: 'View data',
  45. lang: ['View chart data', 'Close', 'Update']
  46. },
  47. magicType: {
  48. show: true,
  49. title: {
  50. pie: 'Switch to pies',
  51. funnel: 'Switch to funnel',
  52. },
  53. type: ['pie', 'funnel'],
  54. option: {
  55. funnel: {
  56. x: '25%',
  57. y: '20%',
  58. width: '50%',
  59. height: '70%',
  60. funnelAlign: 'left',
  61. max: 1548
  62. }
  63. }
  64. },
  65. restore: {
  66. show: true,
  67. title: 'Restore'
  68. },
  69. saveAsImage: {
  70. show: true,
  71. title: 'Same as image',
  72. lang: ['Save']
  73. }
  74. }
  75. },
  76. // Enable drag recalculate
  77. calculable: true,
  78. // Add series
  79. series: [{
  80. name: 'Marketing',
  81. type: 'pie',
  82. radius: '70%',
  83. center: ['50%', '57.5%'],
  84. data: [
  85. {value: 335, name: 'Direct Access'},
  86. {value: 310, name: 'Mail Marketing'},
  87. {value: 234, name: 'Union ad'},
  88. {value: 135, name: 'Video ad'},
  89. {value: 1548, name: 'Search Engine'}
  90. ]
  91. }]
  92. };
  93. basicpieChart.setOption(option);
  94. // ------------------------------
  95. // Basic pie chart
  96. // ------------------------------
  97. // based on prepared DOM, initialize echarts instance
  98. var basicdoughnutChart = echarts.init(document.getElementById('basic-doughnut'));
  99. var option = {
  100. // Add title
  101. title: {
  102. text: 'A site user access source',
  103. subtext: 'Purely Fictitious',
  104. x: 'center'
  105. },
  106. // Add legend
  107. legend: {
  108. orient: 'vertical',
  109. x: 'left',
  110. data: ['Direct Access', 'Mail Marketing', 'Union ad', 'Video ad', 'Search Engine']
  111. },
  112. // Add custom colors
  113. color: ['#689f38', '#38649f', '#389f99', '#ee1044', '#ff8f00'],
  114. // Display toolbox
  115. toolbox: {
  116. show: true,
  117. orient: 'vertical',
  118. feature: {
  119. mark: {
  120. show: true,
  121. title: {
  122. mark: 'Markline switch',
  123. markUndo: 'Undo markline',
  124. markClear: 'Clear markline'
  125. }
  126. },
  127. dataView: {
  128. show: true,
  129. readOnly: false,
  130. title: 'View data',
  131. lang: ['View chart data', 'Close', 'Update']
  132. },
  133. magicType: {
  134. show: true,
  135. title: {
  136. pie: 'Switch to pies',
  137. funnel: 'Switch to funnel',
  138. },
  139. type: ['pie', 'funnel'],
  140. option: {
  141. funnel: {
  142. x: '25%',
  143. y: '20%',
  144. width: '50%',
  145. height: '70%',
  146. funnelAlign: 'left',
  147. max: 1548
  148. }
  149. }
  150. },
  151. restore: {
  152. show: true,
  153. title: 'Restore'
  154. },
  155. saveAsImage: {
  156. show: true,
  157. title: 'Same as image',
  158. lang: ['Save']
  159. }
  160. }
  161. },
  162. // Enable drag recalculate
  163. calculable: true,
  164. // Add series
  165. series: [
  166. {
  167. name: 'Marketing',
  168. type: 'pie',
  169. radius: ['50%', '70%'],
  170. center: ['50%', '57.5%'],
  171. itemStyle: {
  172. normal: {
  173. label: {
  174. show: true
  175. },
  176. labelLine: {
  177. show: true
  178. }
  179. },
  180. emphasis: {
  181. label: {
  182. show: true,
  183. formatter: '{b}' + '\n\n' + '{c} ({d}%)',
  184. position: 'center',
  185. textStyle: {
  186. fontSize: '17',
  187. fontWeight: '500'
  188. }
  189. }
  190. }
  191. },
  192. data: [
  193. {value: 335, name: 'Direct Access'},
  194. {value: 310, name: 'Mail Marketing'},
  195. {value: 234, name: 'Union ad'},
  196. {value: 135, name: 'Video ad'},
  197. {value: 1548, name: 'Search Engine'}
  198. ]
  199. }
  200. ]
  201. };
  202. basicdoughnutChart.setOption(option);
  203. // ------------------------------
  204. // customized chart
  205. // ------------------------------
  206. // based on prepared DOM, initialize echarts instance
  207. var customizedChart = echarts.init(document.getElementById('customized-chart'));
  208. var option = {
  209. backgroundColor: '#fff',
  210. title: {
  211. text: 'Customized Pie',
  212. left: 'center',
  213. top: 20,
  214. textStyle: {
  215. color: '#ccc'
  216. }
  217. },
  218. tooltip : {
  219. trigger: 'item',
  220. formatter: "{a} <br/>{b} : {c} ({d}%)"
  221. },
  222. visualMap: {
  223. show: false,
  224. min: 80,
  225. max: 600,
  226. inRange: {
  227. colorLightness: [0, 1]
  228. }
  229. },
  230. series : [
  231. {
  232. name:'Marketing',
  233. type:'pie',
  234. radius : '55%',
  235. center: ['50%', '50%'],
  236. data:[
  237. {value:335, name:'Direct Access'},
  238. {value:310, name:'Mail Marketing'},
  239. {value:274, name:'Union ad'},
  240. {value:235, name:'Video ad'},
  241. {value:400, name:'Search Engine'}
  242. ].sort(function (a, b) { return a.value - b.value; }),
  243. roseType: 'radius',
  244. label: {
  245. normal: {
  246. textStyle: {
  247. color: 'rgba(0, 0, 0, 0.3)'
  248. }
  249. }
  250. },
  251. labelLine: {
  252. normal: {
  253. lineStyle: {
  254. color: 'rgba(0, 0, 0, 0.3)'
  255. },
  256. smooth: 0.2,
  257. length: 10,
  258. length2: 20
  259. }
  260. },
  261. itemStyle: {
  262. normal: {
  263. color: '#38649f',
  264. shadowBlur: 200,
  265. shadowColor: 'rgba(0, 0, 0, 0.5)'
  266. }
  267. },
  268. animationType: 'scale',
  269. animationEasing: 'elasticOut',
  270. animationDelay: function (idx) {
  271. return Math.random() * 200;
  272. }
  273. }
  274. ]
  275. };
  276. customizedChart.setOption(option);
  277. // ------------------------------
  278. // Nested chart
  279. // ------------------------------
  280. // based on prepared DOM, initialize echarts instance
  281. var nestedChart = echarts.init(document.getElementById('nested-pie'));
  282. var option = {
  283. tooltip: {
  284. trigger: 'item',
  285. formatter: "{a} <br/>{b}: {c} ({d}%)"
  286. },
  287. // Add legend
  288. legend: {
  289. orient: 'vertical',
  290. x: 'left',
  291. data: ['Direct','Marketing Advertising','Search Engine','Mail Marketing','Union ad','Video ad','Baidu','Google','Bing','Other']
  292. },
  293. // Add custom colors
  294. color: ['#689f38', '#38649f', '#389f99', '#ee1044', '#ff8f00'],
  295. // Display toolbox
  296. toolbox: {
  297. show: true,
  298. orient: 'vertical',
  299. feature: {
  300. mark: {
  301. show: true,
  302. title: {
  303. mark: 'Markline switch',
  304. markUndo: 'Undo markline',
  305. markClear: 'Clear markline'
  306. }
  307. },
  308. dataView: {
  309. show: true,
  310. readOnly: false,
  311. title: 'View data',
  312. lang: ['View chart data', 'Close', 'Update']
  313. },
  314. magicType: {
  315. show: true,
  316. title: {
  317. pie: 'Switch to pies',
  318. funnel: 'Switch to funnel',
  319. },
  320. type: ['pie', 'funnel']
  321. },
  322. restore: {
  323. show: true,
  324. title: 'Restore'
  325. },
  326. saveAsImage: {
  327. show: true,
  328. title: 'Same as image',
  329. lang: ['Save']
  330. }
  331. }
  332. },
  333. // Enable drag recalculate
  334. calculable: false,
  335. // Add series
  336. series: [
  337. // Inner
  338. {
  339. name: 'Countries',
  340. type: 'pie',
  341. selectedMode: 'single',
  342. radius: [0, '40%'],
  343. // for funnel
  344. x: '15%',
  345. y: '7.5%',
  346. width: '40%',
  347. height: '85%',
  348. funnelAlign: 'right',
  349. max: 1548,
  350. itemStyle: {
  351. normal: {
  352. label: {
  353. position: 'inner'
  354. },
  355. labelLine: {
  356. show: false
  357. }
  358. },
  359. emphasis: {
  360. label: {
  361. show: true
  362. }
  363. }
  364. },
  365. data: [
  366. {value: 535, name: 'Direct'},
  367. {value: 679, name: 'Marketing ad'},
  368. {value: 1548, name: 'Search Engine'}
  369. ]
  370. },
  371. // Outer
  372. {
  373. name: 'Countries',
  374. type: 'pie',
  375. radius: ['60%', '85%'],
  376. // for funnel
  377. x: '55%',
  378. y: '7.5%',
  379. width: '35%',
  380. height: '85%',
  381. funnelAlign: 'left',
  382. max: 1048,
  383. data: [
  384. {value:335, name: 'Direct'},
  385. {value:310, name: 'Mail Marketing'},
  386. {value:234, name: 'Union ad'},
  387. {value:135, name: 'Video ad'},
  388. {value:1048, name: 'Baidu'},
  389. {value:251, name:'Google'},
  390. {value:147, name: 'Bing'},
  391. {value:102, name:'Other'}
  392. ]
  393. }
  394. ]
  395. };
  396. nestedChart.setOption(option);
  397. // ------------------------------
  398. // pole chart
  399. // ------------------------------
  400. // based on prepared DOM, initialize echarts instance
  401. var poleChart = echarts.init(document.getElementById('pole-chart'));
  402. // Data style
  403. var dataStyle = {
  404. normal: {
  405. label: {show: false},
  406. labelLine: {show: false}
  407. }
  408. };
  409. // Placeholder style
  410. var placeHolderStyle = {
  411. normal: {
  412. color: 'rgba(0,0,0,0)',
  413. label: {show: false},
  414. labelLine: {show: false}
  415. },
  416. emphasis: {
  417. color: 'rgba(0,0,0,0)'
  418. }
  419. };
  420. var option = {
  421. title: {
  422. text: 'Stacked histogram',
  423. subtext: 'Weekly Data',
  424. x: 'center',
  425. y: 'center',
  426. itemGap: 10,
  427. textStyle: {
  428. color: 'rgba(30,144,255,0.8)',
  429. fontSize: 19,
  430. fontWeight: '500'
  431. }
  432. },
  433. // Add tooltip
  434. tooltip: {
  435. show: true,
  436. formatter: "{a} <br/>{b}: {c} ({d}%)"
  437. },
  438. // Add legend
  439. legend: {
  440. orient: 'vertical',
  441. x: document.getElementById('pole-chart').offsetWidth / 2,
  442. y: 30,
  443. x: '55%',
  444. itemGap: 15,
  445. data: ['Monday','Tuesday','Wednesday']
  446. },
  447. // Add custom colors
  448. color: ['#689f38', '#38649f', '#ff8f00'],
  449. // Add series
  450. series: [
  451. {
  452. name: '1',
  453. type: 'pie',
  454. clockWise: false,
  455. radius: ['75%', '90%'],
  456. itemStyle: dataStyle,
  457. data: [
  458. {
  459. value: 60,
  460. name: 'Monday'
  461. },
  462. {
  463. value: 40,
  464. name: 'invisible',
  465. itemStyle: placeHolderStyle
  466. }
  467. ]
  468. },
  469. {
  470. name: '2',
  471. type:'pie',
  472. clockWise: false,
  473. radius: ['60%', '75%'],
  474. itemStyle: dataStyle,
  475. data: [
  476. {
  477. value: 30,
  478. name: 'Tuesday'
  479. },
  480. {
  481. value: 70,
  482. name: 'invisible',
  483. itemStyle: placeHolderStyle
  484. }
  485. ]
  486. },
  487. {
  488. name: '3',
  489. type: 'pie',
  490. clockWise: false,
  491. radius: ['45%', '60%'],
  492. itemStyle: dataStyle,
  493. data: [
  494. {
  495. value: 10,
  496. name: 'Wednesday'
  497. },
  498. {
  499. value: 90,
  500. name: 'invisible',
  501. itemStyle: placeHolderStyle
  502. }
  503. ]
  504. }
  505. ]
  506. };
  507. poleChart.setOption(option);
  508. // ------------------------------
  509. // nightingale chart
  510. // ------------------------------
  511. // based on prepared DOM, initialize echarts instance
  512. var nightingaleChart = echarts.init(document.getElementById('nightingale-chart'));
  513. var option = {
  514. title: {
  515. text: 'Ningdinger Rose Map',
  516. subtext: 'Purely fictitious',
  517. x: 'center'
  518. },
  519. // Add tooltip
  520. tooltip: {
  521. trigger: 'item',
  522. formatter: "{a} <br/>{b}: +{c}$ ({d}%)"
  523. },
  524. // Add legend
  525. legend: {
  526. x: 'left',
  527. y: 'top',
  528. orient: 'vertical',
  529. data:['rose1','rose2','rose3','rose4','rose5','rose6','rose7','rose8']
  530. },
  531. color: ['#689f38', '#e4eaec', '#38649f', '#389f99', '#ee1044', '#ff8f00', '#673ab7', '#4974e0'],
  532. // Display toolbox
  533. toolbox: {
  534. show: true,
  535. orient: 'vertical',
  536. feature: {
  537. mark: {
  538. show: true,
  539. title: {
  540. mark: 'Markline switch',
  541. markUndo: 'Undo markline',
  542. markClear: 'Clear markline'
  543. }
  544. },
  545. dataView: {
  546. show: true,
  547. readOnly: false,
  548. title: 'View data',
  549. lang: ['View chart data', 'Close', 'Update']
  550. },
  551. magicType: {
  552. show: true,
  553. title: {
  554. pie: 'Switch to pies',
  555. funnel: 'Switch to funnel',
  556. },
  557. type: ['pie', 'funnel']
  558. },
  559. restore: {
  560. show: true,
  561. title: 'Restore'
  562. },
  563. saveAsImage: {
  564. show: true,
  565. title: 'Same as image',
  566. lang: ['Save']
  567. }
  568. }
  569. },
  570. // Enable drag recalculate
  571. calculable: true,
  572. // Add series
  573. series: [
  574. {
  575. name: 'Area Mode',
  576. type: 'pie',
  577. radius: ['15%', '73%'],
  578. center: ['50%', '57%'],
  579. roseType: 'area',
  580. // Funnel
  581. width: '40%',
  582. height: '78%',
  583. x: '30%',
  584. y: '17.5%',
  585. max: 450,
  586. sort: 'ascending',
  587. data: [
  588. {value: 440, name: 'rose1'},
  589. {value: 260, name: 'rose2'},
  590. {value: 350, name: 'rose3'},
  591. {value: 250, name: 'rose4'},
  592. {value: 210, name: 'rose5'},
  593. {value: 350, name: 'rose6'},
  594. {value: 300, name: 'rose7'},
  595. {value: 450, name: 'rose8'}
  596. ]
  597. }
  598. ]
  599. };
  600. nightingaleChart.setOption(option);
  601. // ------------------------------
  602. // bar-polar-stack-radial
  603. // ------------------------------
  604. var dom = document.getElementById("bar-polar-stack-radial");
  605. var myChart = echarts.init(dom);
  606. var app = {};
  607. option = null;
  608. app.title = 'Stacked bar chart in polar coordinate system';
  609. option = {
  610. color: ['#689f38', '#38649f', '#389f99'],
  611. angleAxis: {
  612. type: 'category',
  613. data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
  614. z: 10
  615. },
  616. radiusAxis: {
  617. },
  618. polar: {
  619. },
  620. series: [{
  621. type: 'bar',
  622. data: [1, 2, 3, 4, 3, 5, 1],
  623. coordinateSystem: 'polar',
  624. name: 'A',
  625. stack: 'a'
  626. }, {
  627. type: 'bar',
  628. data: [2, 4, 6, 1, 3, 2, 1],
  629. coordinateSystem: 'polar',
  630. name: 'B',
  631. stack: 'a'
  632. }, {
  633. type: 'bar',
  634. data: [1, 2, 3, 4, 1, 2, 5],
  635. coordinateSystem: 'polar',
  636. name: 'C',
  637. stack: 'a'
  638. }],
  639. legend: {
  640. show: true,
  641. data: ['A', 'B', 'C']
  642. }
  643. };
  644. if (option && typeof option === "object") {
  645. myChart.setOption(option, true);
  646. }
  647. //------------------------------------------------------
  648. // Resize chart on menu width change and window resize
  649. //------------------------------------------------------
  650. $(function () {
  651. // Resize chart on menu width change and window resize
  652. $(window).on('resize', resize);
  653. $(".sidebartoggler").on('click', resize);
  654. // Resize function
  655. function resize() {
  656. setTimeout(function() {
  657. // Resize chart
  658. basicpieChart.resize();
  659. basicdoughnutChart.resize();
  660. customizedChart.resize();
  661. nestedChart.resize();
  662. poleChart.resize();
  663. }, 200);
  664. }
  665. });
  666. });