Skip to content
Advertisement

Control the order of visibility of the multiple paths of SVG element

i was searching a way to show an image in html with rounded dashed border like example below

enter image description here

such that number of dashes and their individual colors can be controlled, the similar example can be observed in WhatsApp application status tab where number of dashes changes according to the number of statuses uploaded by user.

Now to address the problem I applied following steps to produce the desired output obviously code is not written by me but I made changes

  1. Generate a Simple Pi chart in SVG using equal values for equal length
  2. Color individual slices according to needs
  3. Display image on top of SVG element actual output or almost near to output results produce

Now in following code I am facing a strange issue which I am not able resolve, the order of the dashed bars are not same e.g. as in the image above the purple color should comes first and then orange and then rest of the gray bars to the end of the circle, but actual output differs.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

Finally i found the solution from the @Michael’s comment, the order was right but the rendering start point was not from the top of the circle so initializing startAngle and endAngle to Math.PI * 1.5 solves the problem e.g. replacing the line

JavaScript

with

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