dingdanzhuangtai.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view>
  3. <div class="chart1" ref="chart1"></div>
  4. </view>
  5. </template>
  6. <script>
  7. import echarts from "echarts";
  8. export default {
  9. props: {
  10. // dinglength:{
  11. // type: String,
  12. // // 定义是否必须传
  13. // required: false,
  14. // // 定义默认值
  15. // default: 0
  16. // },
  17. dingzhuang:{
  18. type: Array,
  19. // 定义是否必须传
  20. required: false,
  21. // 定义默认值
  22. default: []
  23. },
  24. dingnum:{
  25. type: Array,
  26. // 定义是否必须传
  27. required: false,
  28. // 定义默认值
  29. default: []
  30. },
  31. },
  32. watch:{
  33. // dinglength: {
  34. // immediate: true,
  35. // handler(value) {
  36. // this.dinglength = value
  37. // this.getEchartData1()
  38. // }
  39. // },
  40. dingzhuang: {
  41. immediate: true,
  42. handler(value) {
  43. this.dingzhuang = value
  44. this.getEchartData1()
  45. }
  46. },
  47. },
  48. mounted() {
  49. this.getEchartData1()
  50. },
  51. data() {
  52. return {
  53. }
  54. },
  55. methods: {
  56. // 折线图
  57. getEchartData1() {
  58. const chart1 = this.$refs.chart1;
  59. var option = null;
  60. const myChart = this.$echarts.init(chart1);
  61. option = {
  62. tooltip: {
  63. trigger: 'item'
  64. },
  65. color:['rgb(0, 157, 255)','rgb(34, 228, 255)','rgb(59, 255, 208)','rgb(4, 227, 138)',
  66. 'rgb(157, 255, 134)','rgb(254, 229, 136)','rgb(254, 168, 68)','rgb(254, 112, 68)'],
  67. legend: {
  68. top: 'bottom',
  69. bottom:-10
  70. },
  71. series: [
  72. {
  73. name: 'Access From',
  74. type: 'pie',
  75. radius: '50%',
  76. center: ['50%', '40%'],
  77. data: [
  78. { value: this.dingnum[0], name: this.dingzhuang[0] },
  79. { value: this.dingnum[1], name: this.dingzhuang[1] },
  80. { value: this.dingnum[2], name: this.dingzhuang[2] },
  81. { value: this.dingnum[3], name: this.dingzhuang[3] },
  82. { value: this.dingnum[4], name: this.dingzhuang[4] },
  83. { value: this.dingnum[5], name: this.dingzhuang[5] },
  84. { value: this.dingnum[6], name: this.dingzhuang[6] },
  85. { value: this.dingnum[7], name: this.dingzhuang[7] },
  86. { value: this.dingnum[8], name: this.dingzhuang[8] }
  87. ],
  88. emphasis: {
  89. itemStyle: {
  90. shadowBlur: 10,
  91. shadowOffsetX: 0,
  92. shadowColor: 'rgba(0, 0, 0, 0.5)'
  93. }
  94. }
  95. }
  96. ]
  97. };
  98. myChart.setOption(option);
  99. window.addEventListener("resize", function () {
  100. myChart.resize();
  101. });
  102. this.$on("hook:destroyed", () => {
  103. window.removeEventListener("resize", function () {
  104. chart1.resize();
  105. });
  106. });
  107. return option;
  108. },
  109. },
  110. }
  111. </script>
  112. <style>
  113. .chart1 {
  114. width: 100%;
  115. height: 100%;
  116. display: block;
  117. }
  118. </style>