Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
Putting value at 100 doesn't fill up SVG circle. What's wrong with my calculation

I am trying to fill up a SVG circle that has a radius of 13.5. And I have found a calculation but when entering the value as 100 it's only half full. Which believes me there is something wrong with the math part. Putting the value as 225 fills it up fully. And that's not what's desired at all.

SVG:

//Background of progress circle
<circle r="13.5" cx="16" cy="16" fill="transparent" stroke="#9E9E9E" stroke-width="3" stroke-dasharray="84.82300164692441" stroke-dashoffset="28.27433388230813" />
</svg>
//Progress circle
<svg style={{ height: '32px', width: '32px', transform: 'rotate(150deg)' }}>
<circle r="13.5" cx="16" cy="16" fill="transparent" stroke="#000" stroke-width="3" stroke-dasharray={dashArrayValue} stroke-dashoffset={dashOffsetValue} />
</svg>

Calculation code

                let value = 100
                let radius = 13.5
                let circumference = radius * 2 * Math.PI
                let percent = value * 100 / 220
                let offset = circumference - ((-percent * 62) / 100) / 100 * circumference
                let convertedOffset = -offset
                setDashArrayValue(`${circumference}`) //${circumference}
                setDashOffsetValue(`${convertedOffset}`)

Hopefully someone can spot the flaw because I certainly can't since my math is awful.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If it is the dash array that you try to manipulate, here are some examples. YOu can see that I'm just changing two values; the rotation of the circle (where the stroke will start) and the first value in the dash array (the length of the stroke). I allso added the pathLength attribute that controls the total length of the stroke of the circle (in this case 360, but it could also be 100 his that fist better into your use case).

<p>From 12 o'clock to 3 o'clock:
<svg height="32px" width="32px">
  <circle r="13.5" cx="16" cy="16" fill="transparent"
    stroke="#000" stroke-width="3" pathLength="360"
    stroke-dasharray="90 360"
    transform="rotate(-90 16 16)"/>
</svg>
</p>

<p>From 12 o'clock to 6 o'clock:
<svg height="32px" width="32px">
  <circle r="13.5" cx="16" cy="16" fill="transparent"
    stroke="#000" stroke-width="3" pathLength="360"
    stroke-dasharray="180 360"
    transform="rotate(-90 16 16)"/>
</svg>
</p>

<p>From 12 o'clock to 10 o'clock:
<svg height="32px" width="32px">
  <circle r="13.5" cx="16" cy="16" fill="transparent"
    stroke="#000" stroke-width="3" pathLength="360"
    stroke-dasharray="300 360"
    transform="rotate(-90 16 16)"/>
</svg>
</p>

<p>From 6 o'clock to 10 o'clock:
<svg height="32px" width="32px">
  <circle r="13.5" cx="16" cy="16" fill="transparent"
    stroke="#000" stroke-width="3" pathLength="360"
    stroke-dasharray="120 360"
    transform="rotate(90 16 16)"/>
</svg>
</p>

And the interactive version:

document.forms.form01.number.addEventListener('change', e => {
  let number = e.target.value;
  document.getElementById('c1').attributes['stroke-dasharray'].value = `${number} 100`;
});
<form name="form01">
<input name="number" type="range" value="50" min="0" max="100" />
</form>

<p><svg height="32px" width="32px">
  <circle id="c1" r="13.5" cx="16" cy="16" fill="transparent"
    stroke="#000" stroke-width="3" pathLength="100"
    stroke-dasharray="50 100"
    transform="rotate(-90 16 16)"/>
</svg></p>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!