BingChart2.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div class="pie-chart-content">
  3. <div ref="myPieChart" :id="chartId" style="width: 100%; height: 400px"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from "echarts";
  8. export default {
  9. name: "pieChart",
  10. components: {},
  11. props: {
  12. options: {
  13. type: Array,
  14. default: function () {
  15. return [];
  16. },
  17. },
  18. chartId: {
  19. type: String,
  20. default: "",
  21. },
  22. chartName: {
  23. type: String,
  24. default: "",
  25. },
  26. },
  27. data() {
  28. return {
  29. color: ["#FCEF9A", "#D54039", "#56743E", "#FF917C"],
  30. pieData: [],
  31. };
  32. },
  33. // mounted() {
  34. // this.myPieEcharts(this.options);
  35. // },
  36. computed: {},
  37. watch: {
  38. options() {
  39. this.myPieEcharts(this.options);
  40. },
  41. },
  42. methods: {
  43. myPieEcharts(pieData) {
  44. let myChart = this.$echarts.init(document.getElementById(this.chartId));
  45. let option = {
  46. title: {
  47. text: ``,
  48. left: "center",
  49. top:'0px',
  50. textStyle: {
  51. fontSize: 16,
  52. color: "#000000",
  53. foontWeight: "600",
  54. },
  55. },
  56. // tooltip: {
  57. // trigger: "item",
  58. tooltip: {
  59. trigger: "item",
  60. formatter:function(params){
  61. let val = params.marker+params.name+'<br/>'+params.value+'人';
  62. return val
  63. }
  64. },
  65. // },
  66. series: [
  67. {
  68. name: ``,
  69. type: "pie",
  70. radius: "70%",
  71. // label:{
  72. // show:true,
  73. // position:'inner',//将文字显示在行内
  74. // textStyle:{
  75. // fontSize:20,//设置图内显示文字的大小
  76. // color:'#ffffff'//设置饼状图文字的颜色
  77. // }
  78. // },
  79. label:{
  80. show:true,
  81. position:'outside',//将文字显示在行内
  82. textStyle:{
  83. fontSize:16,//设置图内显示文字的大小
  84. color:'#000000'//设置饼状图文字的颜色
  85. }
  86. },
  87. //
  88. // name:100-parseInt(pieData[0].value/(pieData[0].value+ pieData[1].value)*100) + "%"+pieData[1].name,itemStyle:{color:'#FFAE00'
  89. //pieData[0].value :1
  90. data: [
  91. { value: (pieData[0].value==0||pieData[1].value==0)?1:pieData[0].value-pieData[1].value, name:pieData[0].value==0||pieData[1].value==0?'100%心理健康': (100-pieData[1].value/(pieData[0].value)*100).toFixed(2) +'%心理健康',itemStyle:{color:'#5470C6',fontSize:'20'}},
  92. { value:pieData[1].value, name:(pieData[0].value==0||pieData[1].value==0)?'0%中重度焦虑':(pieData[1].value/(pieData[0].value)*100).toFixed(2) + "%"+pieData[1].name,itemStyle:{color:'#FFAE00',fontSize:'20'}},
  93. ],
  94. },
  95. ],
  96. };
  97. pieData && option && myChart.setOption(option);
  98. myChart.resize();
  99. },
  100. pieDataHandle(param) {
  101. this.pieData = [];
  102. // param.groupData.map((item,index) => {
  103. //
  104. // this.lineData.push({
  105. // type: 'line',
  106. // name: item.name,
  107. // data: item.value,
  108. // });
  109. //
  110. // });
  111. //
  112. // this.myLineEcharts(param.category,this.lineData);
  113. },
  114. },
  115. };
  116. </script>
  117. <style scoped>
  118. .pie-chart-content {
  119. width: 100%;
  120. /* height: 100%; */
  121. }
  122. </style>