Skip to content
Advertisement

How to set time according to svg length?

I am learning javascript and react and here I am stuck in the challange that where I have to set time according to SVG image’s length (something like progress bar).

For an ease and basic example, I am calculating total time of 24 hours in 1440 minutes and I have given passed time let passedMins = 1220

Now I need to fill the green line in svg circle according to the time elapse. Like every minute green line should add up more

JavaScript

It looks like this:

Image of circle

It shows 3 lines where I want only one. Any suggestion to fix it?

Advertisement

Answer

You need to also pass the length of the circle to the circle.style.strokeDasharray. To do this, you need to get the length for the “minutes left” in terms of the circle’s total length. Please see example below.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement