warnGradeEchart.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="echartBar">
  3. <div class="bar" ref="bar"></div>
  4. </div>
  5. </template>
  6. <script lang="ts" setup>
  7. import { defineProps, ref, nextTick, reactive, watch } from 'vue';
  8. import * as echarts from 'echarts';
  9. // import { position } from 'html2canvas/dist/types/css/property-descriptors/position';
  10. let props = defineProps({
  11. echartData: {
  12. type: Object,
  13. default: () => {
  14. return {};
  15. },
  16. },
  17. });
  18. //获取dom元素节点
  19. let bar = ref<any>();
  20. let echartDatas = ref<any[]>([]);
  21. watch(
  22. () => props.echartData,
  23. (newV, oldV) => {
  24. let data: any[] = [];
  25. Object.keys(newV).forEach((el) => {
  26. if (el == 'dust') {
  27. data.push({ name: '粉尘', value: newV[el] });
  28. } else if (el == 'fire') {
  29. data.push({ name: '火灾', value: newV[el] });
  30. } else if (el == 'gas') {
  31. data.push({ name: '瓦斯', value: newV[el] });
  32. } else if (el == 'vent') {
  33. data.push({ name: '通风', value: newV[el] });
  34. }
  35. });
  36. echartDatas.value = data;
  37. getOption();
  38. },
  39. { deep: true }
  40. );
  41. function getOption() {
  42. nextTick(() => {
  43. let myChart = echarts.init(bar.value);
  44. let option = {
  45. title: {
  46. text: '风险权重比例',
  47. left: '22%',
  48. top: 5,
  49. textStyle: {
  50. color: '#fff',
  51. fontSize: 14,
  52. },
  53. },
  54. tooltip: {
  55. trigger: 'item',
  56. formatter: '{b} : {c} ({d}%)',
  57. backgroundColor: 'rgba(0, 0, 0, .6)',
  58. textStyle: {
  59. color: '#fff',
  60. fontSize: 12,
  61. },
  62. },
  63. series: [
  64. {
  65. name: '',
  66. type: 'pie',
  67. radius: '50%',
  68. center: ['32%', '50%'],
  69. color: ['rgb(131,249,103)', '#FBFE27', '#FE5050', '#1DB7E5'], //'#FBFE27','rgb(11,228,96)','#FE5050'
  70. data: echartDatas.value,
  71. label: {
  72. normal: {
  73. formatter: ['{c|{c}}', '{b|{b}}'].join('\n'),
  74. rich: {
  75. c: {
  76. color: '#00d8ff',
  77. fontSize: 14,
  78. fontWeight: 'bold',
  79. lineHeight: 5,
  80. },
  81. b: {
  82. color: '#fff',
  83. fontSize: 12,
  84. height: 40,
  85. },
  86. },
  87. },
  88. },
  89. labelLine: {
  90. normal: {
  91. lineStyle: {
  92. color: 'rgb(98,137,169)',
  93. },
  94. smooth: 0.2,
  95. length: 20,
  96. length2: 10,
  97. },
  98. },
  99. itemStyle: {
  100. normal: {
  101. shadowColor: 'rgba(0, 0, 0, 0.8)',
  102. shadowBlur: 50,
  103. },
  104. },
  105. },
  106. ],
  107. };
  108. myChart.setOption(option);
  109. window.onresize = function () {
  110. myChart.resize();
  111. };
  112. });
  113. }
  114. </script>
  115. <style scoped lang="less">
  116. .echartBar {
  117. width: 100%;
  118. height: 100%;
  119. .bar {
  120. width: 100%;
  121. height: 100%;
  122. }
  123. }
  124. </style>