Sun Gauge
A KPI gauge that picks the right scale for each metric: 100 ticks for percentages, 60 for minutes, and a labelled day ruler with a goal marker for days. Built entirely from the Qlik load script as an SVG image. No extensions.
See the Sun Gauge in Qlik
This recording shows the Sun Gauge on a Qlik Sense sheet, driven by the Metric and Month filter panes: Bed occupancy rate on the 100-tick ring, then Average length of stay on the labelled day ruler with its goal marked.
Switching metrics changes the scale — percentages light whole ticks, days read against the ruler and turn red past the goal.
Screen recording only — not a live Qlik connection.
Download qvf
Grab the ready-made Qlik app with the Sun Gauge already set up. Open it in Qlik Sense and it works out of the box — no need to rebuild the load script from scratch. Requires Qlik Sense to open .qvf files.
Download sample data
Healthcare demo workbook with MonthlyMetrics and DepartmentMetrics sheets for the load script below. These are synthetic learning records, not real hospital or patient data.
Live demo
Why three styles?
Percentages → 100 ticks
One tick = 1%. A value of 91.7% lights 92 whole ticks.
Minutes → 60 ticks
Feels like a clock face: one tick = one minute when the goal is 30 minutes.
Days → day ruler
“58 of 100 ticks” means nothing for 4.6 days. A labelled scale with the goal marked and red ticks past it reads at a glance: 4 good days + 0.6 over.
How it works — anatomy
Eight parts, drawn in order. Later parts sit on top.
- 1
OPEN
Canvas 440 × 440, centred viewBox, font.
- 2
DEFS
Disc gradient, halo gradient and mask k (sun ring only).
- 3
RING
Sun ring or day ruler, chosen by the unit.
- 4
DISC
Shaded centre circle.
- 5
TITLE
Metric name.
- 6
VALUE
Big number and unit.
- 7
PILL
Change vs last month (sun ring) or distance from goal (ruler).
- 8
FOOT
Caption, then the closing SVG tag.
Build it in Qlik — step by step
- 1
Load the monthly data: Metric, Month, Value, Unit, Goal, GoalOperator. In MonthlyMetrics, alias Unit as MonthlyUnit, Goal as MonthlyGoal, and GoalOperator as MonthlyGoalOperator. Use %, mins and days for the units; > means higher is better, < means lower is better.
- 2
Add a MetricMonth table: one row per metric and month, with the previous month’s value via Peek().
- 3
For days metrics, build the ruler ticks and labels once in the load script (IterNo() loop + Concat) and join them to MetricMonth.
- 4
Add the colour and helper variables.
- 5
Add the 8 part variables and the final vGaugeSVG. The full script below contains steps 2–5.
- 6
Reload. In a sheet add a straight table with no dimension and one measure =$(vGaugeSVG). Set Representation = Image and image size = Always fit. Hide headers and totals; make the object square.
- 7
Add a filter pane on Metric; with nothing selected the gauge shows Bed Occupancy.
Key tricks
SVG as an image URL
Only # needs encoding in this supplied expression.
'data:image/svg+xml,' & Replace(svg, '#', '%23')Writing %
Use the entity so the URL stays valid.
'%'Opening tags
Some editors/tools choke on raw opening SVG or style tags.
Chr(60)&'svg …'
Chr(60)&'style>'Ticks from one circle
A thick stroke, pathLength and dasharray make equal ticks with no loops.
pathLength=100
stroke-dasharray="0.4 0.6"Whole-tick fill
Round the mask arc to a whole number of ticks.
Round(fill * N) * 100 / NRuler colouring
Colour ticks without loops at chart time. These example selectors light 39 ticks, then mark ticks 42–47 red.
.t line:nth-child(-n+39){stroke:blue}
.t line:nth-child(n+42):nth-child(-n+47){stroke:red}Load-time dollar expansion
Helpers are pasted into the final expression when the script runs; the chart formula stays short.
=$(vGaugeSVG)Pick the row
Choose the selected metric (or Bed Occupancy), then the latest possible month.
FirstSortedValue(svg, If(GetSelectedCount(Metric)=1 or G_Metric='Bed Occupancy',0,100000) - G_Month)Customise
| What to change | Which variable |
|---|---|
| Colours | vG_TickOn, vG_TickOff, vG_Good, vG_Bad, … |
| Tick count for % / minutes | vG_N (and vG_Dash for tick width) |
| Which metrics use the ruler | vG_Day (currently unit = days) |
| Ruler scale | Goal × 2, 10 ticks per unit (RulerTmp / RulerTicks) |
| Display names | vG_Name |
Full script
///$tab SunGauge
// ---- Sun gauge: radial ticks lit in proportion to the value, value and change vs last month in the middle ----
// % metrics: 100 ticks (1 tick = 1%). mins metrics: 60 ticks.
// days metrics: a labelled day ruler (1 tick = 0.1 day) on a 300-degree arc, goal marked, ticks past the goal in red.
// Use as an image URL (e.g. a straight table with no dimension, measure representation = Image): =$(vGaugeSVG)
// Shows the selected metric (Bed Occupancy when none or several are selected) for the latest possible month.
// Value of every metric per month (average over all observations) and the value of the month before.
MetricMonthTmp:
LOAD Metric AS G_Metric, Month AS G_Month,
Avg(Value) AS G_Value,
MaxString(MonthlyUnit) AS G_Unit,
Max(MonthlyGoal) AS G_Goal,
MaxString(MonthlyGoalOperator) AS G_Op
RESIDENT MonthlyMetrics
GROUP BY Metric, Month;
MetricMonth:
LOAD G_Metric & '|' & Text(G_Month) AS MetricMonthKey,
G_Metric, G_Month, G_Value, G_Unit, G_Goal, G_Op,
If(G_Metric = Peek('G_Metric'), Peek('G_Value')) AS G_Prev
RESIDENT MetricMonthTmp
ORDER BY G_Metric, G_Month;
DROP TABLE MetricMonthTmp;
// Colours
SET vG_TickOn = '#4A90D9'; // lit ticks
SET vG_TickOff = '#D9DFE7'; // unlit ticks
SET vG_DiscTop = '#F7FAFD'; // centre disc, light middle
SET vG_DiscEdge = '#E4ECF6'; // centre disc, edge
SET vG_DiscLine = '#C9D5E3'; // centre disc outline
SET vG_Glow = '#E3EDF8'; // soft halo behind the ticks
SET vG_Title = '#2B3445'; // metric name
SET vG_Value = '#151B26'; // big number
SET vG_Muted = '#6B7280'; // vs last month, ruler labels
SET vG_Good = '#2E7D4F'; // change in the right direction
SET vG_GoodBg = '#F0FAF3';
SET vG_Bad = '#C0392B'; // change in the wrong direction, ruler ticks past the goal
SET vG_BadBg = '#FDF1F0';
SET vG_Font = Segoe UI,system-ui,-apple-system,Helvetica Neue,Roboto,Arial,sans-serif;
// ---- Day ruler (days metrics only), built once here: scale 0 to 2 x goal, 10 ticks per day, a label per day ----
// Arc runs clockwise from -150 to +150 degrees (0 = 12 o'clock); every 10th tick (whole day) is longer.
RulerTmp:
LOAD G_Metric, Ceil(Max(G_Goal) * 2) AS G_RMax, Max(G_Goal) AS G_RGoal
RESIDENT MetricMonth WHERE G_Unit = 'days' GROUP BY G_Metric;
RulerTicks:
LOAD G_Metric, Concat(T, '', i) AS G_RTicks GROUP BY G_Metric;
LOAD G_Metric, i, '<line x1="'&Num(r1*Sin(a),'0.0')&'" y1="'&Num(-r1*Cos(a),'0.0')&'" x2="'&Num(212*Sin(a),'0.0')&'" y2="'&Num(-212*Cos(a),'0.0')&'"/>' AS T;
LOAD G_Metric, i, If(Mod(i, 10) = 0, 176, 186) AS r1, (-150 + 300 * i / (G_RMax * 10)) * Pi() / 180 AS a;
LOAD G_Metric, G_RMax, IterNo() - 1 AS i RESIDENT RulerTmp WHILE IterNo() <= G_RMax * 10 + 1;
RulerLabels:
LOAD G_Metric, Concat(T, '', j) AS G_RLabels GROUP BY G_Metric;
LOAD G_Metric, j, '<text x="'&Num(160*Sin(a),'0.0')&'" y="'&Num(5 - 160*Cos(a),'0.0')&'"'&If(j = G_RGoal, ' font-size="15" font-weight="700" fill="$(vG_Title)">Goal '&j, '>'&j)&'</text>' AS T;
LOAD G_Metric, G_RGoal, j, (-150 + 300 * j / G_RMax) * Pi() / 180 AS a;
LOAD G_Metric, G_RGoal, G_RMax, IterNo() - 1 AS j RESIDENT RulerTmp WHILE IterNo() <= G_RMax + 1;
LEFT JOIN (MetricMonth) LOAD G_Metric, G_RMax RESIDENT RulerTmp;
LEFT JOIN (MetricMonth) LOAD G_Metric, G_RTicks RESIDENT RulerTicks;
LEFT JOIN (MetricMonth) LOAD G_Metric, G_RLabels RESIDENT RulerLabels;
DROP TABLES RulerTmp, RulerTicks, RulerLabels;
// Helpers (pasted into the parts below when the script runs)
SET vG_Pick = If(GetSelectedCount(Metric) = 1 or G_Metric = 'Bed Occupancy', 0, 100000) - G_Month; // which metric and month
SET vG_Fill = RangeMin(1, RangeMax(0, If(G_Unit = '%', G_Value / 100, G_Value / (G_Goal * 2)))); // share of the ring lit
SET vG_N = If(G_Unit = '%', 100, 60); // sun ring: number of ticks
SET vG_Dash = If(G_Unit = '%', 0.4, 0.3); // sun ring: tick width (share of one tick step)
SET vG_Day = (G_Unit = 'days'); // true = draw the day ruler instead of the sun ring
SET vG_Lit = RangeMin(G_RMax * 10 + 1, Round(G_Value * 10) + 1); // ruler: ticks lit (tick 1 = 0 days)
SET vG_GoalT = (Round(G_Goal * 10) + 1); // ruler: the goal tick
SET vG_Delta = (G_Value - G_Prev);
SET vG_IsGood = ((G_Op = '>' and $(vG_Delta) >= 0) or (G_Op = '<' and $(vG_Delta) <= 0));
SET vG_DTxt = (If($(vG_Delta) >= 0, '↑ ', '↓ ') & Num(Fabs($(vG_Delta)), If(G_Unit = 'mins', '0', '0.0')) & If(G_Unit = '%', ' pp', If(G_Unit = 'mins', ' min', ' days')));
SET vG_GoalOk = If(G_Op = '<', G_Value <= G_Goal, G_Value >= G_Goal); // ruler pill: on the right side of the goal
SET vG_GTxt = (If(G_Value > G_Goal, Num(G_Value - G_Goal, '0.0') & ' days over goal', If(G_Value < G_Goal, Num(G_Goal - G_Value, '0.0') & ' days under goal', 'On goal')));
SET vG_Name = If(Match(G_Metric, 'Bed Occupancy', 'Discharges Before Noon', 'Length of Stay', 'Wait Time'), Pick(Match(G_Metric, 'Bed Occupancy', 'Discharges Before Noon', 'Length of Stay', 'Wait Time'), 'Bed occupancy rate', 'Discharges before noon', 'Average length of stay', 'Average wait time'), G_Metric);
// =====================================================================================================
// The gauge image, built from 8 parts, drawn in this order (later parts sit on top).
// The canvas is centred on 0,0 (viewBox -220 -220 440 440), so every shape and text is placed from the middle
// and text is centred by default. Reload after changing a part.
// =====================================================================================================
// 1. OPEN - the 440 x 440 canvas and the font. (Only the opening tag needs Chr(60) for "<".)
SET vG_S_Open = (Chr(60)&'svg xmlns="http:'&Chr(47)&Chr(47)&'www.w3.org/2000/svg" width="440" height="440" viewBox="-220 -220 440 440" font-family="$(vG_Font)" text-anchor="middle">');
// 2. DEFS - reusable pieces, not drawn on their own:
// d = centre disc shading, h = soft halo behind the ticks,
// k = the sun ring mask: an arc from 12 o'clock as long as the value (whole ticks only); it grows in over 1.4 s.
SET vG_S_Defs = ('<defs><radialGradient id="d" cy=".4" r=".65"><stop stop-color="'&vG_DiscTop&'"/><stop offset="1" stop-color="'&vG_DiscEdge&'"/></radialGradient><radialGradient id="h"><stop offset=".6" stop-color="'&vG_Glow&'" stop-opacity="0"/><stop offset="1" stop-color="'&vG_Glow&'" stop-opacity=".9"/></radialGradient><mask id="k"><circle r="196" fill="none" stroke="#fff" stroke-width="40" pathLength="100" stroke-dasharray="'&Num(Round($(vG_Fill) * $(vG_N)) * 100 / $(vG_N), '0.00')&' 100"><animate attributeName="stroke-dasharray" from="0 100" to="'&Num(Round($(vG_Fill) * $(vG_N)) * 100 / $(vG_N), '0.00')&' 100" dur="1.4s" calcMode="spline" keyTimes="0;1" keySplines=".2 .7 .2 1"/></circle></mask></defs>');
// 3. RING
// Sun ring (% and mins): the halo, then grey ticks, then the same ticks in blue seen only through mask k.
// A tick is a short dash of a thick circle line: pathLength = one unit per tick, dash = tick width.
// Day ruler (days): the ticks and labels built above; a small style block colours the first ticks blue
// and, for "lower is better" metrics, the ticks between the goal and the value red.
SET vG_S_Ring = (If($(vG_Day),
Chr(60)&'style>.t line{stroke:'&vG_TickOff&';stroke-width:3;stroke-linecap:round}.t line:nth-child(10n+1){stroke-width:4}.t line:nth-child(-n+'&$(vG_Lit)&'){stroke:'&vG_TickOn&'}'&If(G_Op = '<' and $(vG_Lit) > $(vG_GoalT), '.t line:nth-child(n+'&($(vG_GoalT) + 1)&'):nth-child(-n+'&$(vG_Lit)&'){stroke:'&vG_Bad&'}')&Chr(60)&'/style><g class="t">'&G_RTicks&'</g><g font-size="13" fill="'&vG_Muted&'">'&G_RLabels&'</g>',
'<circle r="218" fill="url(#h)"/><g fill="none" stroke-width="30" stroke-dasharray="'&$(vG_Dash)&' '&(1 - $(vG_Dash))&'" stroke-dashoffset="'&(-(1 - $(vG_Dash)) / 2)&'" transform="rotate(-90)"><circle r="196" pathLength="'&$(vG_N)&'" stroke="'&vG_TickOff&'"/><circle r="196" pathLength="'&$(vG_N)&'" stroke="'&vG_TickOn&'" mask="url(#k)"/></g>'));
// 4. DISC - the shaded centre circle with a thin outline (a little smaller with the day ruler, to fit the labels).
SET vG_S_Disc = ('<circle r="'&If($(vG_Day), 140, 152)&'" fill="url(#d)" stroke="'&vG_DiscLine&'" stroke-width="1.5"/>');
// 5. TITLE - the metric name.
SET vG_S_Title = ('<text y="'&If($(vG_Day), -50, -55)&'" font-size="'&If($(vG_Day), 20, 21)&'" fill="'&vG_Title&'">'&$(vG_Name)&'</text>');
// 6. VALUE - the big number and its smaller unit (% is written % so the image URL stays valid).
SET vG_S_Value = ('<text y="'&If($(vG_Day), 40, 48)&'" font-size="'&If($(vG_Day), 86, 92)&'" font-weight="600" letter-spacing="-2" fill="'&vG_Value&'">'&Num(G_Value, If(G_Unit = 'mins', '0', '0.0'))&'<tspan font-size="'&If($(vG_Day), 32, 34)&'" font-weight="500" dx="6">'&If(G_Unit = '%', '%', If(G_Unit = 'mins', 'min', G_Unit))&'</tspan></text>');
// 7. PILL
// Sun ring: change vs the month before, green when it moves the right way, red when not (left out with no earlier month).
// Day ruler: distance from the goal ("0.6 days over goal"), green on the right side of the goal, red when not.
SET vG_S_Pill = (If($(vG_Day),
'<rect x="'&Num(-(28 + Len($(vG_GTxt)) * 7.4) / 2, '0.0')&'" y="58" width="'&Num(28 + Len($(vG_GTxt)) * 7.4, '0.0')&'" height="34" rx="17" fill="'&If($(vG_GoalOk), vG_GoodBg, vG_BadBg)&'" stroke="'&If($(vG_GoalOk), vG_Good, vG_Bad)&'" stroke-width="1.5"/><text y="81" font-size="15" font-weight="600" fill="'&If($(vG_GoalOk), vG_Good, vG_Bad)&'">'&$(vG_GTxt)&'</text>',
If(Len(G_Prev), '<rect x="'&Num(-(34 + Len($(vG_DTxt)) * 9.6) / 2, '0.0')&'" y="66" width="'&Num(34 + Len($(vG_DTxt)) * 9.6, '0.0')&'" height="38" rx="19" fill="'&If($(vG_IsGood), vG_GoodBg, vG_BadBg)&'" stroke="'&If($(vG_IsGood), vG_Good, vG_Bad)&'" stroke-width="1.5"/><text y="91" font-size="17" font-weight="600" fill="'&If($(vG_IsGood), vG_Good, vG_Bad)&'">'&$(vG_DTxt)&'</text>')));
// 8. FOOT - the small caption, then the end of the SVG.
SET vG_S_Foot = (If($(vG_Day),
'<text y="114" font-size="13" fill="'&vG_Muted&'">1 tick = 0.1 day'&If(Len(G_Prev), ' · '&If($(vG_Delta) >= 0, '↑ ', '↓ ')&Num(Fabs($(vG_Delta)), '0.0')&' vs last month')&'</text></svg>',
'<text y="132" font-size="14" fill="'&vG_Muted&'">'&If(Len(G_Prev), 'vs last month', 'no earlier month')&'</text></svg>'));
// FINAL - join the parts, turn # into %23 (the only character an image URL needs encoded here),
// and pick one metric/month: the selected metric (or Bed Occupancy) for the latest possible month.
// Use in a chart as an image URL: =$(vGaugeSVG)
SET vGaugeSVG = (FirstSortedValue('data:image/svg+xml,'&Replace($(vG_S_Open)&$(vG_S_Defs)&$(vG_S_Ring)&$(vG_S_Disc)&$(vG_S_Title)&$(vG_S_Value)&$(vG_S_Pill)&$(vG_S_Foot), '#', '%23'), $(vG_Pick)));Paste into a new SunGauge tab in the Qlik data load editor, after loading MonthlyMetrics. Reload after editing.
Troubleshooting
Image is blank
A # wasn’t encoded, or a raw % slipped in; check the final Replace.
All ticks lit / none lit
Check G_Unit values match %, mins, days exactly.
Ruler is missing
The metric’s unit isn’t days, or the ruler tables weren’t joined. Reload after editing.
Mask arc is offset by 90°
You rotated the mask circle as well as the tick group; remove the mask rotation.
Fonts look different
SVG images can’t load web fonts; the system font stack is intentional.
