dual-pie-chart.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="chart" :id="id"></div>
  3. </template>
  4. <script>
  5. import util from "@/helper/util.js";
  6. import partten from "@/helper/partten.js";
  7. import * as echarts from "echarts";
  8. import { left } from "@antv/x6/lib/registry/port-layout/line";
  9. export default {
  10. name: "dsah-pie",
  11. componentName: "dsah-pie",
  12. props: {
  13. width: {
  14. type: String,
  15. default: "100%",
  16. },
  17. height: {
  18. type: String,
  19. default: "18.519vh",
  20. },
  21. paddingWidth: {
  22. type: String,
  23. default: "30%",
  24. },
  25. // 饼图数据
  26. series: {
  27. type: Array,
  28. default: () => [],
  29. },
  30. // 颜色
  31. color: {
  32. type: String,
  33. default: "green",
  34. },
  35. showLegend: {
  36. type: Boolean,
  37. default: true,
  38. },
  39. title: { type: String, default: "" },
  40. },
  41. data() {
  42. return {
  43. id: "",
  44. chart: null,
  45. };
  46. },
  47. computed: {},
  48. methods: {
  49. initChart() {
  50. let that = this;
  51. // let legend1 = this.innerData.map((v) => v.name);
  52. // let legend2 = this.outerData.map((v) => v.name);
  53. // let legendData = [...legend1, ...legend2];
  54. let option = {
  55. title: {
  56. text: this.title,
  57. textStyle: {
  58. fontSize: 16,
  59. color: "rgba(255, 255, 255, 0.75)",
  60. fontWeight: 400,
  61. },
  62. left: "center",
  63. },
  64. tooltip: {
  65. trigger: "item",
  66. formatter: function (params) {
  67. console.log(params);
  68. return params.marker + params.name + " " + params.value + "%";
  69. },
  70. },
  71. legend: {
  72. orient: "vertical",
  73. // left: "left",
  74. right: "right",
  75. top: "center",
  76. textStyle: {
  77. color: "rgba(255, 255, 255, 0.75)",
  78. },
  79. },
  80. series: [
  81. {
  82. name: "",
  83. type: "pie",
  84. radius: "50%",
  85. data: this.series || [],
  86. label: {
  87. normal: {
  88. show: false,
  89. },
  90. },
  91. labelLine: {
  92. normal: {
  93. show: false,
  94. },
  95. },
  96. // emphasis: {
  97. // itemStyle: {
  98. // shadowBlur: 10,
  99. // shadowOffsetX: 0,
  100. // shadowColor: "rgba(0, 0, 0, 0.5)",
  101. // },
  102. // },
  103. },
  104. ],
  105. };
  106. this.chart.setOption(option);
  107. },
  108. },
  109. created() {
  110. this.id = "pie-chart-" + util.newGUID();
  111. },
  112. mounted() {
  113. this.$el.style.width = this.width;
  114. this.$el.style.height = this.height;
  115. this.chart = echarts.init(this.$el);
  116. this.initChart();
  117. },
  118. updated() {
  119. this.initChart();
  120. },
  121. watch: {
  122. "$store.state.themeName"() {
  123. this.initChart();
  124. },
  125. },
  126. };
  127. </script>
  128. <style lang="less" scoped>
  129. .chart {
  130. width: 100%;
  131. height: 100%;
  132. display: block;
  133. margin: auto;
  134. }
  135. </style>