HTML
<!-- ↓SVGの円形プログレスバー ====================== -->
<div class="progress_circle" data-percent="0">
<svg viewBox="-10 -10 220 220">
<g fill="none" stroke-width="10" transform="translate(100,100)">
<path d="M 0,-100 A 100,100 0 0,1 86.6,-50" stroke="url(#cl1)" />
<path d="M 86.6,-50 A 100,100 0 0,1 86.6,50" stroke="url(#cl2)" />
<path d="M 86.6,50 A 100,100 0 0,1 0,100" stroke="url(#cl3)" />
<path d="M 0,100 A 100,100 0 0,1 -86.6,50" stroke="url(#cl4)" />
<path d="M -86.6,50 A 100,100 0 0,1 -86.6,-50" stroke="url(#cl5)" />
<path d="M -86.6,-50 A 100,100 0 0,1 0,-100" stroke="url(#cl6)" />
</g>
</svg>
<svg viewBox="-10 -10 220 220">
<path
d="M200,100 C200,44.771525 155.228475,0 100,0 C44.771525,0 0,44.771525 0,100 C0,155.228475 44.771525,200 100,200 C155.228475,200 200,155.228475 200,100 Z"
stroke-dashoffset="0"></path>
</svg>
<progress value="0" min="0" max="100"></progress>
</div>
<!-- ↑SVGの円形プログレスバー ====================== -->
<!-- ↓SVGのグラデーション色定義 ====================== -->
<svg width="0" height="0">
<defs>
<linearGradient id="cl1" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="1" y2="1">
<stop stop-color="#33ABDB"/>
<stop offset="100%" stop-color="#0F9AE5"/>
</linearGradient>
<linearGradient id="cl2" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="0" y2="1">
<stop stop-color="#0F9AE5"/>
<stop offset="100%" stop-color="#33ABDB"/>
</linearGradient>
<linearGradient id="cl3" gradientUnits="objectBoundingBox" x1="1" y1="0" x2="0" y2="1">
<stop stop-color="#33ABDB"/>
<stop offset="100%" stop-color="#4EB8D4"/>
</linearGradient>
<linearGradient id="cl4" gradientUnits="objectBoundingBox" x1="1" y1="1" x2="0" y2="0">
<stop stop-color="#4EB8D4"/>
<stop offset="100%" stop-color="#7FCFC7"/>
</linearGradient>
<linearGradient id="cl5" gradientUnits="objectBoundingBox" x1="0" y1="1" x2="0" y2="0">
<stop stop-color="#7FCFC7"/>
<stop offset="100%" stop-color="#4EB8D4"/>
</linearGradient>
<linearGradient id="cl6" gradientUnits="objectBoundingBox" x1="0" y1="1" x2="1" y2="0">
<stop stop-color="#4EB8D4"/>
<stop offset="100%" stop-color="#33ABDB"/>
</linearGradient>
</defs>
</svg>
<!-- ↑SVGの色定義 ====================== -->
<!-- ↓数値の入力欄 -->
<input id="percent_input" type="number" min="0" max="100" value="0" /> %
<!-- ↑数値の入力欄 -->
JavaScript
/**
* SVG円形プログレスバーの更新
* @type {HTMLElement} progressCircleElem プログレスバーの枠要素
* @type {HTMLElement} pathElem svgのpath要素
* @type {string} value 文字列の数値 (0〜100)
*/
function updateProgressCircle(progressCircleElem, pathElem, value) {
const STROKE_DASHARRAY_VALUE = 629;
progressCircleElem.querySelector('progress').value = value;
progressCircleElem.dataset.percent = value;
const dashoffset = Math.round(STROKE_DASHARRAY_VALUE * 100 / 100 * Number(value) / 100);
pathElem.setAttribute('stroke-dashoffset', dashoffset);
}
window.addEventListener('load', function () {
// 初期化
const INIT_VALUE = 0;
const progressCircleElem = document.querySelector('.progress_circle');
const pathElem = progressCircleElem.querySelector('svg path[stroke-dashoffset]');
updateProgressCircle(progressCircleElem, pathElem, INIT_VALUE);
// 擬似的に、入力欄に入れた値をプログレスバーへ反映
const percentInputElem = document.getElementById('percent_input');
percentInputElem.addEventListener('input', (event) => {
updateProgressCircle(progressCircleElem, pathElem, event.target.value);
});
});