echart-circle.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}"></div>
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. // require('echarts/theme/macarons') // echarts theme
  7. export default {
  8. props: {
  9. className: {
  10. type: String,
  11. default: 'chart'
  12. },
  13. width: {
  14. type: String,
  15. default: '100%'
  16. },
  17. height: {
  18. type: String,
  19. default: '240px'
  20. },
  21. chartData: {
  22. type: Object
  23. }
  24. // autoResize: {
  25. // type: Boolean,
  26. // default: true
  27. // }
  28. },
  29. data() {
  30. return {
  31. chart: null
  32. }
  33. },
  34. watch: {
  35. chartData: {
  36. deep: true,
  37. handler: function(val) {
  38. if (!this.chart) {
  39. return false
  40. }
  41. let chartData = JSON.parse(JSON.stringify(val))
  42. this.setOptions(chartData)
  43. }
  44. }
  45. },
  46. mounted() {
  47. // this.initChart()
  48. },
  49. methods: {
  50. initChart() {
  51. let data = {
  52. date: ['6.15', '6.16', '6.17', '6.18', '6.19', '6.20', '6.21'],
  53. // accessNum: [10, 332, 301, 50, 390, 80, 320],
  54. guestNum: [10, 332, 301, 50, 390, 80, 320]
  55. }
  56. // this.chart = echarts.init(this.$el, 'macarons')
  57. this.chart = echarts.init(this.$el)
  58. let chartData = JSON.parse(JSON.stringify(this.chartData))
  59. // this.setOptions(chartData)
  60. this.setOptions(data)
  61. },
  62. setOptions(chartData) {
  63. this.chart.setOption({
  64. tooltip: {
  65. trigger: 'item',
  66. formatter: '{a} <br/>{b} : {c} ({d}%)'
  67. },
  68. legend: {
  69. orient: 'vertical',
  70. left: 'right',
  71. data: ['门店 50% 158', '微信朋友圈 33.33% 134', '美团 16.67% 24']
  72. },
  73. series: [
  74. {
  75. name: '访问来源',
  76. type: 'pie',
  77. radius: '70%',
  78. center: ['40%', '50%'],
  79. data: [{ value: 335, name: '门店 50% 158' }, { value: 310, name: '微信朋友圈 33.33% 134' }, { value: 234, name: '美团 16.67% 24' }],
  80. emphasis: {
  81. itemStyle: {
  82. shadowBlur: 10,
  83. shadowOffsetX: 0,
  84. shadowColor: 'rgba(0, 0, 0, 0.5)'
  85. }
  86. }
  87. }
  88. ]
  89. })
  90. }
  91. },
  92. filters: {}
  93. }
  94. </script>