PieChart2.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="pie-chart-content">
  3. <div ref="myPieChart" :id="chartId" style="width: 100%; height: 200px"></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "pieChart",
  9. components: {},
  10. props: {
  11. options: {
  12. type: Array,
  13. default: function () {
  14. return [];
  15. },
  16. },
  17. chartId: {
  18. type: String,
  19. default: "",
  20. },
  21. chartName: {
  22. type: String,
  23. default: "",
  24. },
  25. },
  26. data() {
  27. return {
  28. color: ["#FCEF9A", "#D54039", "#56743E", "#FF917C"],
  29. pieData: [],
  30. };
  31. },
  32. // mounted() {
  33. // this.myPieEcharts(this.options);
  34. // },
  35. computed: {},
  36. watch: {
  37. options() {
  38. this.myPieEcharts(this.options);
  39. },
  40. },
  41. methods: {
  42. myPieEcharts(pieData) {
  43. console.log("pieData", pieData);
  44. let myChart = this.$echarts.init(document.getElementById(this.chartId));
  45. console.log(myChart);
  46. //配置图表
  47. let option = {
  48. title: {
  49. text: this.chartName,
  50. subtext: "百分比",
  51. left: "center",
  52. top: "60%",
  53. },
  54. tooltip: {
  55. trigger: "item",
  56. },
  57. legend: {
  58. orient: "vertical",
  59. left: "left",
  60. // top: "38%",
  61. // bottom:0
  62. },
  63. series: [
  64. {
  65. name: "",
  66. type: "pie",
  67. radius: "40%",
  68. center: ["50%", "40%"],
  69. // data: [
  70. // { value: 1048, name: 'Search Engine' },
  71. // { value: 735, name: 'Direct' },
  72. // { value: 580, name: 'Email' },
  73. // { value: 484, name: 'Union Ads' },
  74. // { value: 300, name: 'Video Ads' }
  75. // ],
  76. data: pieData,
  77. emphasis: {
  78. itemStyle: {
  79. shadowBlur: 10,
  80. shadowOffsetX: 0,
  81. shadowColor: "rgba(0, 0, 0, 0.5)",
  82. },
  83. },
  84. },
  85. ],
  86. };
  87. pieData && option && myChart.setOption(option);
  88. window.onresize = function () {
  89. myChart.resize();
  90. };
  91. },
  92. pieDataHandle(param) {
  93. this.pieData = [];
  94. // param.groupData.map((item,index) => {
  95. //
  96. // this.lineData.push({
  97. // type: 'line',
  98. // name: item.name,
  99. // data: item.value,
  100. // });
  101. //
  102. // });
  103. //
  104. // this.myLineEcharts(param.category,this.lineData);
  105. },
  106. },
  107. };
  108. </script>
  109. <style scoped>
  110. .pie-chart-content {
  111. width: 100%;
  112. height: 100%;
  113. }
  114. </style>