randarPage.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <script setup lang="ts">
  2. import { onMounted, defineProps, nextTick, watch ,ref} from 'vue'
  3. import * as echarts from 'echarts';
  4. const props = defineProps({
  5. randarList: Array // 或者根据你的需求,使用其他类型
  6. });
  7. const list = ref([0,0,0,0])
  8. const echartsRander = (randarList) => {
  9. const dom = document.getElementById('chartsId');
  10. if (!dom) return;
  11. const myChart = echarts.init(dom);
  12. const option = {
  13. color: ['#56A3F1'],
  14. radar: {
  15. center: ['51%', '50%'], // 设置雷达图的中心位置,避免坐标轴名称被遮挡
  16. radius: '58%',
  17. indicator: [
  18. { name: '自我介绍专业性', max: 25 },
  19. { name: '客户画像采集', max: 25 },
  20. { name: '需求挖掘能力', max: 25 },
  21. { name: '沟通转化效果', max: 25 }
  22. ],
  23. axisName: {
  24. color: '#fff',
  25. backgroundColor: '#666',
  26. borderRadius: 3,
  27. padding: [3, 3]
  28. }
  29. },
  30. series: [
  31. {
  32. type: 'radar',
  33. data: [
  34. {
  35. symbol: 'rect',
  36. symbolSize: 8,
  37. lineStyle: {
  38. type: 'dashed'
  39. },
  40. value: randarList,
  41. label: {
  42. show: true,
  43. formatter: function (params) {
  44. return params.value;
  45. }
  46. },
  47. }
  48. ]
  49. }
  50. ]
  51. };
  52. option && myChart.setOption(option);
  53. window.addEventListener('resize', function () {
  54. myChart.resize();
  55. });
  56. }
  57. // onMounted(() => {
  58. // nextTick(()=>{
  59. // console.log(props.randarList,'00000000000')
  60. // echartsRander(props.randarList)
  61. // })
  62. // // echartsRander(props.randarList)
  63. // })
  64. onMounted(() => {
  65. nextTick(() => {
  66. if (props.randarList && props.randarList.length > 0) {
  67. list.value = props.randarList;
  68. echartsRander(props.randarList);
  69. }
  70. });
  71. });
  72. // 使用 watch 来观察 props.randarList 的变化
  73. watch(() => props.randarList, (newVal, oldVal) => {
  74. if (newVal && newVal.length > 0) {
  75. list.value = newVal
  76. echartsRander(newVal);
  77. }
  78. });
  79. </script>
  80. <template>
  81. <!-- <div> -->
  82. <div id="chartsId" style="width: 100%;height: 100%;"></div>
  83. <!-- <div v-else>暂无数据</div> -->
  84. <!-- </div> -->
  85. </template>