Radar.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div>
  3. <div style="width: 100%; height: 160px" id="radar"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { ref, onMounted, computed, inject, onBeforeUnmount } from "vue";
  8. import { mapState } from "vuex";
  9. import exchangeUrl from "utils/exchangeUrl";
  10. export default {
  11. setup() {
  12. let echarts = inject("ec");
  13. let radartDom = ref({});
  14. let radarChart = ref({});
  15. function init() {
  16. radartDom.value = document.getElementById("radar");
  17. radarChart.value = echarts.init(radartDom.value, "dark");
  18. radarChart.value.setOption(option.value);
  19. }
  20. function updateData(data = [300, 900, 800, 100, 700]) {
  21. option.value.series[0].data[0].value = data;
  22. radarChart.value.setOption(option.value);
  23. }
  24. let option = ref({
  25. title: {},
  26. radar: {
  27. center: ["50%", 90],
  28. // shape: 'circle',
  29. indicator: [
  30. { name: "数据1", max: 1000 },
  31. { name: "数据2", max: 1000 },
  32. { name: "数据3", max: 1000 },
  33. { name: "数据4", max: 1000 },
  34. { name: "数据5", max: 1000 },
  35. ],
  36. axisLine: {
  37. // (圆内的几条直线)坐标轴轴线相关设置
  38. lineStyle: {
  39. color: "#45FAFF",
  40. // 坐标轴线线的颜色。
  41. width: 1,
  42. // 坐标轴线线宽。
  43. type: "solid",
  44. // 坐标轴线线的类型。
  45. },
  46. },
  47. splitLine: {
  48. // (这里是指所有圆环)坐标轴在 grid 区域中的分隔线。
  49. lineStyle: {
  50. color: "#45FAFF",
  51. // 分隔线颜色
  52. width: 1,
  53. // 分隔线线宽
  54. },
  55. },
  56. splitArea: {
  57. // 坐标轴在 grid 区域中的分隔区域,默认不显示。
  58. show: true,
  59. areaStyle: {
  60. // 分隔区域的样式设置。
  61. color: ["rgba(250,250,250,0)", "rgba(200,200,200,0)"],
  62. // 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
  63. },
  64. },
  65. },
  66. series: [
  67. {
  68. symbolSize: 1,
  69. name: "Budget vs spending",
  70. type: "radar",
  71. data: [
  72. {
  73. value: [650, 300, 100, 900, 500],
  74. },
  75. ],
  76. areaStyle: {
  77. // 单项区域填充样式
  78. color: "rgb(69,250,255)", // 填充的颜色。[ default: "#000" ]
  79. opacity: 1,
  80. },
  81. color: "#45FAFF",
  82. },
  83. ],
  84. backgroundColor: "rgba(0, 0, 0, 0)",
  85. });
  86. onMounted(() => {
  87. let t = setTimeout(() => {
  88. init();
  89. }, 100);
  90. });
  91. onBeforeUnmount(() => {
  92. radarChart.value.dispose();
  93. });
  94. return {
  95. init,
  96. exchangeUrl,
  97. updateData,
  98. };
  99. },
  100. };
  101. </script>
  102. <style lang="scss" scoped>
  103. </style>