index5.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div
  3. ref="echartD"
  4. style="width:100%;height:100%;"
  5. ></div>
  6. </template>
  7. <script>
  8. export default {
  9. props: {
  10. dataMap: Object
  11. },
  12. data() {
  13. return {
  14. data:[]
  15. };
  16. },
  17. watch: {
  18. dataMap(val,old){
  19. console.log(val)
  20. this.getData(val)
  21. }
  22. },
  23. mounted() {
  24. this.getData();
  25. },
  26. methods: {
  27. getData(data = this.dataMap) {
  28. console.log(data)
  29. let that = this
  30. let echartsMap = this.$echarts.getInstanceByDom(this.$refs.echartD);
  31. if (echartsMap == null) {
  32. echartsMap = this.$echarts.init(this.$refs.echartD);
  33. }
  34. let colorList = [
  35. '#b72727',
  36. '#c3a102',
  37. '#3f8a3f',
  38. '#009b8a',
  39. ]
  40. for(let i=0;i<data.length;i++){
  41. data[i].label = {
  42. color: colorList[i]
  43. }
  44. }
  45. let option = {
  46. color: [
  47. '#b72727',
  48. '#c3a102',
  49. '#3f8a3f',
  50. '#009b8a',
  51. ],
  52. legend: {
  53. // icon:'rect',
  54. itemWidth: 20,
  55. // orient: 'vertical',
  56. bottom: 0,
  57. textStyle: {
  58. show: true,
  59. color: "#fff",
  60. fontSize: "0.175rem",
  61. fontFamily: "syhtN",
  62. width: this.isVs ? 0 : 85,
  63. overflow: "truncate",
  64. },
  65. },
  66. series: [
  67. {
  68. name: '',
  69. type: 'pie',
  70. radius: [40, 80],
  71. center: ['50%', '50%'],
  72. roseType: 'area',
  73. itemStyle: {
  74. normal: {
  75. label: {
  76. show: true,
  77. position: 'outer',
  78. fontSize: "0.175rem",
  79. lineHeight:18,
  80. align: "bottom",
  81. color:"#fff",
  82. formatter: function (data) { //指示线对应文字,说明文字
  83. return `${data.data.name}\n${data.data.value}`;
  84. },
  85. textStyle: {
  86. fontSize: 14,
  87. },
  88. },
  89. labelLine: { //指示线状态
  90. show: true,
  91. length: 10,
  92. length2: 10,
  93. position:"bottom"
  94. }
  95. }
  96. },
  97. data:data
  98. }
  99. ]
  100. };
  101. echartsMap.setOption(option);
  102. option && echartsMap.setOption(option);
  103. setTimeout(function () {
  104. window.onresize = function () {
  105. echartsMap.resize();
  106. };
  107. }, 200);
  108. },
  109. },
  110. };
  111. </script>