1
0

randarPage.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: 15 },
  19. { name: '产品优势包装', max: 35 },
  20. { name: '客户购车需求', max: 10},
  21. { name: '客户画像采集', max: 20 },
  22. { name: '沟通转化效果', max: 20 }
  23. ],
  24. axisName: {
  25. color: '#fff',
  26. backgroundColor: '#666',
  27. borderRadius: 3,
  28. padding: [3, 3]
  29. }
  30. },
  31. series: [
  32. {
  33. type: 'radar',
  34. data: [
  35. {
  36. symbol: 'rect',
  37. symbolSize: 8,
  38. lineStyle: {
  39. type: 'dashed'
  40. },
  41. value: randarList,
  42. label: {
  43. show: true,
  44. formatter: function (params) {
  45. return params.value;
  46. }
  47. },
  48. }
  49. ]
  50. }
  51. ]
  52. };
  53. option && myChart.setOption(option);
  54. window.addEventListener('resize', function () {
  55. myChart.resize();
  56. });
  57. }
  58. // onMounted(() => {
  59. // nextTick(()=>{
  60. // console.log(props.randarList,'00000000000')
  61. // echartsRander(props.randarList)
  62. // })
  63. // // echartsRander(props.randarList)
  64. // })
  65. onMounted(() => {
  66. nextTick(() => {
  67. if (props.randarList && props.randarList.length > 0) {
  68. list.value = props.randarList;
  69. echartsRander(props.randarList);
  70. }
  71. });
  72. });
  73. // 使用 watch 来观察 props.randarList 的变化
  74. watch(() => props.randarList, (newVal, oldVal) => {
  75. if (newVal && newVal.length > 0) {
  76. list.value = newVal
  77. echartsRander(newVal);
  78. }
  79. });
  80. </script>
  81. <template>
  82. <!-- <div> -->
  83. <div id="chartsId" style="width: 100%;height: 100%;"></div>
  84. <!-- <div v-else>暂无数据</div> -->
  85. <!-- </div> -->
  86. </template>