Skip to content
Advertisement

Divide semi circle with stroke-dasharray and on active color fill

I’m working on an SVG gauge meter here I want to divide the semi-circle into parts when the range slider move on active stroke fill with gradient color. And want to add one more black color running track when the meter needle moves. I had tried using stroke-dasharray but after adding this all colors are coming at a time meter is not working properly.

  1. I want to divide the semi-circle into parts when the range slider move on active stroke fill with gradient color
  2. And I want to add one more black color running track when the meter needle moves.

My code here

JavaScript
JavaScript
JavaScript

Can anyone suggest to me how to achieve this output. Any help will be appreciate.

JavaScript
enter image description here

Advertisement

Answer

Here’s a working SVG example, with a little bit of javascript.

It’s not clear from your question what exactly you want the coloured divisions to look like. For now I’ve just made them solid red. But you can make them look however you’d like by changing the fill of the <rect id="meter-colours" .../>.

JavaScript
JavaScript
JavaScript

Update re new needle image

First let’s simplify your needle image:

JavaScript

To use this in your meter, we’ll need to locate an accurate centre of rotation (the dot in the circle), and re-orient it so that it has zero angle. We may also need to adjust its scale to fit the meter.

By analysis and experimentation, the centre of rotation is at (10.44, 41.3) and the rotation needed to zero out the rotation is 35.8 deg.

Since the meter is centred at (0,0) we need to start by shifting and rotating the new needle by those amounts.

JavaScript

The needle is now horizontal, and positioned at (0,0).

We can now integrate it into the previous solution:

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