• vue 封装水球图


    1、 安装 echarts 与 echarts-liquidfill

    1. pnpm i echarts
    2. pnpm i echarts-liquidfill

    2、组件中引入

    1. import * as echarts from 'echarts'
    2. import 'echarts-liquidfill'

    3、封装通用组件

    1. class="waterball-chart">
    2. <div ref="chartContainer" style="width: 100%; height: 90%">div>
    1. import { ref, onMounted, watch } from 'vue'
    2. import * as echarts from 'echarts'
    3. import 'echarts-liquidfill'
    4. const props = defineProps<{
    5. borderColor: any
    6. titleInfo: any
    7. percentage: any
    8. color: any
    9. labelNumber: any
    10. percentSize: any
    11. unitSize: any
    12. padding: any
    13. }>()
    14. const chartContainer = ref(null)
    15. // ----------------------------------
    16. const drawWaterball = (percentage: any) => {
    17. const chart = echarts.init(chartContainer.value)
    18. const option = {
    19. series: [
    20. {
    21. type: 'liquidFill',
    22. data: [percentage / 100], // 百分比的值,取值范围为0到1
    23. color: [props.color],
    24. radius: '85%', // 水球图的半径,可以根据需要调整
    25. label: {
    26. formatter(param: any) {
    27. return [
    28. `{a|${props.labelNumber || (param.value * 100).toFixed(0)}}`,
    29. '{b|%}',
    30. ].join('')
    31. },
    32. rich: {
    33. a: {
    34. fontSize: props.percentSize,
    35. color: '#FFFFFF',
    36. fontFamily: 'DINPro',
    37. fontWeight: 400,
    38. },
    39. b: {
    40. fontSize: props.unitSize,
    41. color: '#FFFFFF',
    42. fontFamily: 'DINPro-Regular',
    43. fontWeight: 400,
    44. padding: props.padding,
    45. },
    46. },
    47. },
    48. title: {
    49. text: `${(0.2 * 100).toFixed(0)}{a|%}`,
    50. textStyle: {
    51. fontSize: 12,
    52. fontFamily: 'Microsoft Yahei',
    53. fontWeight: 'normal',
    54. color: '#bcb8fb',
    55. rich: {
    56. a: {
    57. fontSize: 10,
    58. },
    59. },
    60. },
    61. x: 'center',
    62. y: '35%',
    63. },
    64. backgroundStyle: {
    65. color: {
    66. type: 'radial',
    67. x: 0.5,
    68. y: 0.5,
    69. r: 0.8,
    70. colorStops: [
    71. {
    72. offset: 0,
    73. color: 'rgba(204, 230, 255,1)', // 0% 处的颜色
    74. },
    75. {
    76. offset: 0.5,
    77. color: 'rgba(204, 230, 255, 1)', // 0% 处的颜色
    78. },
    79. {
    80. offset: 1,
    81. color: 'rgba(204, 230, 255, 1)', // 100% 处的颜色
    82. },
    83. ],
    84. globalCoord: false, // 缺省为 false
    85. },
    86. },
    87. outline: {
    88. // show:false,
    89. borderDistance: 0,
    90. itemStyle: {
    91. borderWidth: 10,
    92. borderColor: props.borderColor,
    93. },
    94. },
    95. },
    96. ],
    97. }
    98. setTimeout(() => {
    99. chart.resize()
    100. chart.setOption(option)
    101. }, 8)
    102. }
    103. // ---------------------------------
    104. watch(
    105. () => props.percentage,
    106. (newValue) => {
    107. drawWaterball(newValue)
    108. },
    109. )
    110. // ---------------------------------
    111. onMounted(() => {
    112. drawWaterball(props.percentage)
    113. })

    4、效果图

  • 相关阅读:
    DHCP服务器的部署使用
    三、数学建模之非线性规划
    Java 中的线程池
    分布式事务框架 Seata 入门案例
    Ubuntu下载odbc驱动
    Ajax零基础入门 Ajax零基础入门第三天 3.5 jQuery高级用法 && 3.6 axios
    Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
    单细胞论文记录(part18)--Spectral clustering based on learning similarity matrix
    HTMl案例二:注册页面
    第十一章 GetAway服务网关详解
  • 原文地址:https://blog.csdn.net/weixin_46263560/article/details/139436186