LiquidChart.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!-- 水球图 -->
  2. <template>
  3. <div :id="id" :class="className" :style="{ height, width }" />
  4. </template>
  5. <script setup lang="ts">
  6. import * as echarts from "echarts";
  7. import "echarts-liquidfill";
  8. const props = defineProps({
  9. id: {
  10. type: String,
  11. default: "liquidChart",
  12. required: true,
  13. },
  14. className: {
  15. type: String,
  16. default: "chart",
  17. },
  18. width: {
  19. type: String,
  20. default: "160px",
  21. },
  22. height: {
  23. type: String,
  24. default: "160px",
  25. },
  26. color: {
  27. type: String,
  28. default: "#2f539b",
  29. },
  30. bgColor: {
  31. type: String,
  32. default: "#e6e8f9",
  33. },
  34. data: {
  35. type: Number,
  36. default: 0,
  37. required: true,
  38. },
  39. });
  40. const options = {
  41. series: [
  42. {
  43. type: "liquidFill", // 水球图样式
  44. radius: "90%",
  45. center: ["50%", "50%"], // 水球图位置
  46. amplitude: 5, // 波浪波动起伏大小
  47. waveLength: "50%", // 波浪长度
  48. color: [props.bgColor], // 波浪颜色
  49. itemStyle: {
  50. opacity: 1, //波浪透明度
  51. shadowBlur: 0, //波浪阴影
  52. },
  53. backgroundStyle: {
  54. backgroundColor: "#ffffff",
  55. color: "#ffffff", // 内部球背景颜色
  56. borderWidth: 0, // 内部球边框宽度
  57. borderColor: "#ffffff", // 内部球边框颜色
  58. },
  59. outline: {
  60. borderDistance: 5, // 外边框与内边框间的距离
  61. itemStyle: {
  62. borderWidth: 5, // 外边框的宽度
  63. borderColor: props.color,
  64. },
  65. },
  66. label: {
  67. formatter: props.data,
  68. color: props.color, // 在波浪上方时的文字颜色
  69. insideColor: "#ffffff", // 在波浪下方时的文字颜色
  70. fontSize: 30, // 文字大小
  71. },
  72. data: [props.data / 100], // 水球的注满度 60%
  73. },
  74. ],
  75. };
  76. onMounted(() => {
  77. const chart = echarts.init(
  78. document.getElementById(<string>props.id) as HTMLDivElement
  79. );
  80. chart.setOption(options);
  81. window.addEventListener("resize", () => {
  82. chart.resize();
  83. });
  84. });
  85. </script>