pie.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <script src="data/pie-texture.js"></script>
  7. <script src="lib/dat.gui.min.js"></script>
  8. </head>
  9. <body>
  10. <style>
  11. html, body, #main {
  12. width: 100%;
  13. height: 100%;
  14. background-image: url(old_mathematics.png);
  15. background-repeat: repeat;
  16. }
  17. </style>
  18. <div id="main"></div>
  19. <script>
  20. require([
  21. 'echarts',
  22. 'echarts/chart/pie',
  23. 'echarts/component/legend',
  24. 'echarts/component/grid',
  25. 'echarts/component/tooltip',
  26. 'echarts/component/toolbox'
  27. ], function (echarts) {
  28. var chart = echarts.init(document.getElementById('main'));
  29. // Pencil sketch texture
  30. var patternSrc = window.pieTexture;
  31. var img = new Image();
  32. img.src = patternSrc;
  33. var itemStyle = {
  34. normal: {
  35. opacity: 0.7,
  36. color: {
  37. image: img,
  38. repeat: 'repeat'
  39. },
  40. borderWidth: 3,
  41. borderColor: '#235894'
  42. // shadowBlur: 10,
  43. // shadowOffsetX: 0,
  44. // shadowOffsetY: 5,
  45. // shadowColor: 'rgba(0, 0, 0, 0.4)'
  46. }
  47. };
  48. chart.setOption({
  49. legend: {
  50. data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
  51. },
  52. toolbox: {
  53. left: 'left',
  54. feature: {
  55. dataView: {},
  56. saveAsImage: {}
  57. }
  58. },
  59. tooltip: {},
  60. series: [{
  61. name: 'pie',
  62. type: 'pie',
  63. selectedMode: 'single',
  64. selectedOffset: 30,
  65. clockwise: true,
  66. label: {
  67. normal: {
  68. textStyle: {
  69. fontSize: 18,
  70. color: '#333'
  71. }
  72. }
  73. },
  74. labelLine: {
  75. normal: {
  76. lineStyle: {
  77. color: '#333'
  78. }
  79. }
  80. },
  81. data:[
  82. {value:335, name:'直接访问'},
  83. {value:310, name:'邮件营销'},
  84. {value:234, name:'联盟广告'},
  85. {value:135, name:'视频广告'},
  86. {value:1548, name:'搜索引擎'}
  87. ],
  88. itemStyle: itemStyle
  89. }]
  90. });
  91. var config = {
  92. labelPosition: 'outside',
  93. clockwise: true,
  94. labelLineLen: 20,
  95. labelLineLen2: 5
  96. };
  97. function update() {
  98. chart.setOption({
  99. series: [{
  100. name: 'pie',
  101. clockwise: config.clockwise,
  102. label: {
  103. normal: {
  104. position: config.labelPosition
  105. }
  106. },
  107. labelLine: {
  108. normal: {
  109. length: config.labelLineLen,
  110. length2: config.labelLineLen2
  111. }
  112. }
  113. }]
  114. });
  115. }
  116. var gui = new dat.GUI();
  117. gui.add(config, 'clockwise')
  118. .onChange(update);
  119. gui.add(config, 'labelPosition', ['inside', 'outside'])
  120. .onChange(update);
  121. gui.add(config, 'labelLineLen', 0, 100)
  122. .onChange(update);
  123. gui.add(config, 'labelLineLen2', 0, 100)
  124. .onChange(update);
  125. })
  126. </script>
  127. </body>
  128. </html>