legendPie.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div :id="id" style="height: 100%;width:100%;"></div>
  3. </template>
  4. <script>
  5. export default {
  6. data () {
  7. return {}
  8. },
  9. props:{
  10. id:{
  11. type: String
  12. }
  13. },
  14. mounted(){
  15. this.drawLine();
  16. },
  17. methods:{
  18. drawLine(){
  19. let _this = this
  20. // 基于准备好的dom,初始化echarts实例
  21. let myChart = this.$echarts.init(document.getElementById(this.id));
  22. myChart.setOption({
  23. tooltip: {
  24. trigger: 'item',
  25. formatter: "{a} <br/>{b}: {c} ({d}%)"
  26. },
  27. series: [
  28. {
  29. name:'访问来源',
  30. type:'pie',
  31. radius: ['50%', '70%'],
  32. avoidLabelOverlap: false,
  33. label: {
  34. normal: {
  35. show: false,
  36. position: 'center',
  37. formatter: '{text|{b}}\n{value|{d}%}',
  38. rich: {
  39. text: {
  40. color: "#fefefe",
  41. // fontSize: 14,
  42. align: 'center',
  43. verticalAlign: 'middle',
  44. padding: 5
  45. },
  46. value: {
  47. color: "#fefefe",
  48. // fontSize: 24,
  49. align: 'center',
  50. verticalAlign: 'middle',
  51. },
  52. }
  53. },
  54. emphasis: {
  55. show: true,
  56. textStyle: {
  57. fontSize: 46,
  58. }
  59. }
  60. },
  61. labelLine: {
  62. normal: {
  63. show: false
  64. }
  65. },
  66. data:[
  67. {value:335, name:'直接访问'},
  68. {value:310, name:'邮件营销'},
  69. {value:234, name:'联盟广告'},
  70. {value:135, name:'视频广告'},
  71. {value:1548, name:'搜索引擎'}
  72. ]
  73. }
  74. ]
  75. });
  76. myChart.dispatchAction({
  77. type: 'highlight',
  78. // seriesIndex: 1,
  79. dataIndex: 2
  80. });
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. </style>