radar.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <script setup lang="ts">
  2. import { ref, computed, nextTick } from "vue";
  3. import { useDark, useECharts } from "@pureadmin/utils";
  4. // 兼容dark主题
  5. const { isDark } = useDark();
  6. let theme = computed(() => {
  7. return isDark.value ? "dark" : "default";
  8. });
  9. // 初始化ECharts
  10. const chartRef = ref();
  11. const { setOptions } = useECharts(chartRef, { theme });
  12. const rankName = ref([]);
  13. const rankValue = ref([]);
  14. // 根据配置项渲染ECharts
  15. const initChart = (item?: any) => {
  16. rankName.value = [];
  17. rankValue.value = [];
  18. console.log("根据配置项渲染ECharts", item);
  19. if (item && item.length != 0) {
  20. item.map(itx => {
  21. itx.dimensionList.map(it => {
  22. rankName.value.push({
  23. name: it.dimName
  24. });
  25. rankValue.value.push(it.soreRate);
  26. });
  27. });
  28. setOptions({
  29. tooltip: {},
  30. legend: {
  31. // icon: "arrow",
  32. itemWidth: 25,
  33. itemHeight: 4,
  34. data: ["得分率"],
  35. top: 10,
  36. left: "left"
  37. },
  38. radar: {
  39. radius: "70%", // 调整半径以使雷达图更大
  40. indicator: rankName.value,
  41. axisName: {
  42. color: "black"
  43. }
  44. },
  45. series: [
  46. {
  47. name: "得分率",
  48. type: "radar",
  49. areaStyle: {
  50. normal: {
  51. color: "rgba(0, 128, 255, 0.2)" // 设置内部填充颜色和透明度
  52. }
  53. },
  54. lineStyle: {
  55. normal: {
  56. width: 1, // 设置线条宽度为 1
  57. color: "rgba(0, 128, 255, 1)" // 设置线条颜色
  58. }
  59. },
  60. data: [
  61. {
  62. value: rankValue.value
  63. // name: "支出"
  64. }
  65. ]
  66. }
  67. ]
  68. });
  69. }
  70. };
  71. nextTick(() => {
  72. initChart();
  73. });
  74. // initChart();
  75. defineExpose({ initChart });
  76. </script>
  77. <template>
  78. <div ref="chartRef" class="w-72 h-64 m-auto mt-2" />
  79. </template>