pie.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. }
  14. </style>
  15. <div id="main"></div>
  16. <script>
  17. require([
  18. 'echarts',
  19. 'echarts/chart/pie',
  20. 'echarts/component/legend',
  21. 'echarts/component/grid',
  22. 'echarts/component/tooltip',
  23. 'echarts/component/toolbox'
  24. ], function (echarts) {
  25. var chart = echarts.init(document.getElementById('main'));
  26. var itemStyle = {
  27. normal: {
  28. // shadowBlur: 10,
  29. // shadowOffsetX: 0,
  30. // shadowOffsetY: 5,
  31. // shadowColor: 'rgba(0, 0, 0, 0.4)'
  32. }
  33. };
  34. chart.setOption({
  35. legend: {
  36. data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
  37. },
  38. toolbox: {
  39. left: 'left',
  40. feature: {
  41. dataView: {},
  42. saveAsImage: {}
  43. }
  44. },
  45. tooltip: {},
  46. series: [{
  47. name: 'pie',
  48. type: 'pie',
  49. selectedMode: 'single',
  50. selectedOffset: 30,
  51. clockwise: true,
  52. data:[
  53. {value:335, name:'直接访问'},
  54. {value:310, name:'邮件营销'},
  55. {value:234, name:'联盟广告'},
  56. {value:135, name:'视频广告'},
  57. {value:1548, name:'搜索引擎'}
  58. ],
  59. itemStyle: itemStyle
  60. }]
  61. });
  62. var config = {
  63. labelPosition: 'outside',
  64. clockwise: true,
  65. labelLineLen: 20,
  66. labelLineLen2: 5
  67. };
  68. function update() {
  69. chart.setOption({
  70. series: [{
  71. name: 'pie',
  72. clockwise: config.clockwise,
  73. label: {
  74. normal: {
  75. position: config.labelPosition
  76. }
  77. },
  78. labelLine: {
  79. normal: {
  80. length: config.labelLineLen,
  81. length2: config.labelLineLen2
  82. }
  83. }
  84. }]
  85. });
  86. }
  87. var gui = new dat.GUI();
  88. gui.add(config, 'clockwise')
  89. .onChange(update);
  90. gui.add(config, 'labelPosition', ['inside', 'outside'])
  91. .onChange(update);
  92. gui.add(config, 'labelLineLen', 0, 100)
  93. .onChange(update);
  94. gui.add(config, 'labelLineLen2', 0, 100)
  95. .onChange(update);
  96. })
  97. </script>
  98. </body>
  99. </html>