RadarChart.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!-- 雷达图 -->
  2. <template>
  3. <el-card>
  4. <template #header> 订单状态雷达图 </template>
  5. <div :id="id" :class="className" :style="{ height, width }"></div>
  6. </el-card>
  7. </template>
  8. <script setup lang="ts">
  9. import * as echarts from "echarts";
  10. const props = defineProps({
  11. id: {
  12. type: String,
  13. default: "radarChart",
  14. },
  15. className: {
  16. type: String,
  17. default: "",
  18. },
  19. width: {
  20. type: String,
  21. default: "200px",
  22. required: true,
  23. },
  24. height: {
  25. type: String,
  26. default: "200px",
  27. required: true,
  28. },
  29. });
  30. const options = {
  31. grid: {
  32. left: "2%",
  33. right: "2%",
  34. bottom: "10%",
  35. containLabel: true,
  36. },
  37. legend: {
  38. x: "center",
  39. y: "bottom",
  40. data: ["预定数量", "下单数量", "发货数量"],
  41. textStyle: {
  42. color: "#999",
  43. },
  44. },
  45. radar: {
  46. // shape: 'circle',
  47. radius: "60%",
  48. indicator: [
  49. { name: "家用电器" },
  50. { name: "服装箱包" },
  51. { name: "运动户外" },
  52. { name: "手机数码" },
  53. { name: "汽车用品" },
  54. { name: "家具厨具" },
  55. ],
  56. },
  57. series: [
  58. {
  59. name: "Budget vs spending",
  60. type: "radar",
  61. itemStyle: {
  62. borderRadius: 6,
  63. color: function (params: any) {
  64. //自定义颜色
  65. const colorList = ["#409EFF", "#67C23A", "#E6A23C", "#F56C6C"];
  66. return colorList[params.dataIndex];
  67. },
  68. },
  69. data: [
  70. {
  71. value: [400, 400, 400, 400, 400, 400],
  72. name: "预定数量",
  73. },
  74. {
  75. value: [300, 300, 300, 300, 300, 300],
  76. name: "下单数量",
  77. },
  78. {
  79. value: [200, 200, 200, 200, 200, 200],
  80. name: "发货数量",
  81. },
  82. ],
  83. },
  84. ],
  85. };
  86. const chart = ref<any>("");
  87. onMounted(() => {
  88. chart.value = markRaw(
  89. echarts.init(document.getElementById(props.id) as HTMLDivElement)
  90. );
  91. chart.value.setOption(options);
  92. window.addEventListener("resize", () => {
  93. chart.value.resize();
  94. });
  95. });
  96. onActivated(() => {
  97. if (chart.value) {
  98. chart.value.resize();
  99. }
  100. });
  101. </script>