funnel.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <script src="lib/dat.gui.min.js"></script>
  7. </head>
  8. <body>
  9. <style>
  10. html, body, #main {
  11. width: 100%;
  12. height: 100%;
  13. margin: 0;
  14. }
  15. </style>
  16. <div id="main"></div>
  17. <script>
  18. require([
  19. 'echarts',
  20. 'echarts/chart/funnel',
  21. 'echarts/component/legend',
  22. 'echarts/component/grid',
  23. 'echarts/component/tooltip',
  24. 'echarts/component/title'
  25. ], function (echarts) {
  26. var chart = echarts.init(document.getElementById('main'), null, {
  27. renderer: 'canvas'
  28. });
  29. var itemStyle = {
  30. normal: {
  31. borderWidth: 0
  32. },
  33. emphasis: {
  34. shadowBlur: 40,
  35. shadowOffsetX: 0,
  36. shadowOffsetY: 0,
  37. shadowColor: 'rgba(0, 0, 0, 0.4)',
  38. borderWidth: 2
  39. }
  40. };
  41. chart.setOption({
  42. title : {
  43. text: '漏斗图',
  44. subtext: '纯属虚构'
  45. },
  46. tooltip : {
  47. trigger: 'item',
  48. formatter: '{a} <br/>{b} : {c}%'
  49. },
  50. legend: {
  51. data : ['展现','点击','访问','咨询','订单']
  52. },
  53. series: [
  54. {
  55. name:'漏斗图',
  56. type:'funnel',
  57. gap: 3,
  58. itemStyle: itemStyle,
  59. left: 300,
  60. right: 300,
  61. sort: 'ascending',
  62. label: {
  63. normal: {
  64. position: 'inside'
  65. }
  66. },
  67. data:[
  68. {value:60, name:'访问'},
  69. {value:40, name:'咨询'},
  70. {value:20, name:'订单'},
  71. {value:80, name:'点击'},
  72. {value:100, name:'展现'}
  73. ]
  74. }
  75. ]
  76. });
  77. var config = {
  78. sort: 'ascending',
  79. labelPosition: 'inside',
  80. labelLineLen: 20
  81. };
  82. function update() {
  83. chart.setOption({
  84. series: [{
  85. name: '漏斗图',
  86. sort: config.sort,
  87. label: {
  88. normal: {
  89. position: config.labelPosition
  90. }
  91. },
  92. labelLine: {
  93. normal: {
  94. length: config.labelLineLen
  95. }
  96. }
  97. }]
  98. });
  99. }
  100. var gui = new dat.GUI();
  101. gui.add(config, 'sort', ['descending', 'ascending'])
  102. .onChange(update);
  103. gui.add(config, 'labelPosition', ['inside', 'left', 'right'])
  104. .onChange(update);
  105. gui.add(config, 'labelLineLen', 0, 100)
  106. .onChange(update);
  107. });
  108. </script>
  109. </body>
  110. </html>