Switch 10: Wider-track circular switch
This is a small variation of Switch 9. The only change is the track width: 74 instead of 72. The knob positions (26 and 59) and the animation are unchanged, so the knob sits with a little more room on the right when ON.
This preview demonstrates the appearance only and is not connected to a live Qlik app. In Qlik, a separate button action must change vSwitch between 0 and 1.
The Qlik expression
Paste into a measure displayed as an image.
='data:image/svg+xml;utf8,' &
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 90 50" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">' &
'<rect x="8" y="5" width="74" height="40" rx="20" fill="' & If($(vSwitch)=1,'%234052c5','%23e7eaf2') & '" stroke="%23d7dae1" stroke-width="2">' &
'<animate attributeName="fill" from="' & If($(vSwitch)=1,'%23e7eaf2','%234052c5') & '" to="' & If($(vSwitch)=1,'%234052c5','%23e7eaf2') & '" dur="0.2s" fill="freeze"/>' &
'</rect>' &
'<circle cx="' & If($(vSwitch)=1,'59','26') & '" cy="25" r="17" fill="%23ffffff" stroke="%23c5c7cb" stroke-width="2.5">' &
'<animate attributeName="cx" from="' & If($(vSwitch)=1,'26','59') & '" to="' & If($(vSwitch)=1,'59','26') & '" dur="0.2s" fill="freeze"/>' &
'</circle>' &
'</svg>'How the expression works
- 1
Data URI and viewBox
'data:image/svg+xml;utf8,' & '<svg ... viewBox="0 0 90 50" ...>'Inline SVG on a 90×50 grid that scales to fit the Qlik object.
- 2
The one change: track width
<rect x="8" y="5" width="74" height="40" rx="20" ...>width="74" replaces width="72" from Switch 9. Everything else in the track stays the same.
- 3
Conditional track colour
If($(vSwitch)=1,'%234052c5','%23e7eaf2')Blue when vSwitch is 1, pale grey when 0. # is written as %23 so the data URI stays valid.
- 4
Same circular knob
<circle ... cy="25" r="17" fill="%23ffffff" stroke="%23c5c7cb">Identical to Switch 9.
- 5
Unchanged knob positions
cx="' & If($(vSwitch)=1,'59','26') & '"Still 59 when ON and 26 when OFF. Because the track is 2 units wider, the ON knob has slightly more space at the right end.
- 6
Optional animation
<animate attributeName="cx" ... dur="0.2s" fill="freeze"/>Slides the knob from the old position to the new one whenever Qlik re-renders the image.
Qlik setup
Done in your Qlik app, separate from the preview above. vSwitch must be 0 (OFF) or 1 (ON).
1. Create the variable
In edit mode, open Variables and create vSwitch starting at 0.
Name: vSwitch
Definition: 02. Add a button action
Button → Set variable value → vSwitch, with this value.
=1-$(vSwitch)3. Place the expression in an object that renders images (e.g. a Text & image measure shown as an image), next to or under the button.
Troubleshooting
I can barely see a difference from Switch 9+
That's expected — it's a 2-unit change. To centre the ON knob in the wider track, you could move the ON cx from 59 to 61.
The image is broken or blank+
Check every colour uses %23 instead of #, quotes are balanced, and the measure is shown as an image.
The switch never changes+
The SVG only draws the state. Confirm vSwitch is 0 or 1 and that a separate Qlik button action toggles it with =1-$(vSwitch).