示例效果:

源码:

获取需要的值后可以通过js来修改–value值,和text的值。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Circle Chart</title>
    <style>
        .circle-chart-item {
            width: 200px;
        }

        .circle-chart-item svg {
            width: 100%;
            height: auto;
        }

        .circle-chart-item circle {
            stroke-width: 2;
            fill: none;
            cx: 17;
            cy: 17;
            r: 16;
        }

        .circle-chart-item circle:nth-child(1) {
            stroke: #efefef;
        }

        .circle-chart-item circle:nth-child(2) {
            stroke: #00acc1;
            stroke-linecap: round;
            stroke-dasharray: 0 100;
            animation: circle-chart 0.6s ease-in-out forwards;
            transform: rotate(-90deg);
            transform-origin: center;
        }

        .circle-chart-item text {
            font-size: 8px;
            text-anchor: middle;
            dominant-baseline: middle;
            user-select: none;
        }

        @keyframes circle-chart {
            from {
                stroke-dasharray: 0 100;
            }

            to {
                stroke-dasharray: var(--value, 0) 100;
            }
        }
    </style>
</head>

<body>
    <div class="circle-chart-item" style="--value:20">
        <svg viewBox="0 0 34 34" xmlns="http://www.w3.org/2000/svg">
            <circle />
            <circle />
            <text x="17" y="17">20%</text>
        </svg>
    </div>
</body>

</html>