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.

Pure SVGNo extensionLoad-script driven
Video

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

Loading gauge…

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. 1

    OPEN

    Canvas 440 × 440, centred viewBox, font.

  2. 2

    DEFS

    Disc gradient, halo gradient and mask k (sun ring only).

  3. 3

    RING

    Sun ring or day ruler, chosen by the unit.

  4. 4

    DISC

    Shaded centre circle.

  5. 5

    TITLE

    Metric name.

  6. 6

    VALUE

    Big number and unit.

  7. 7

    PILL

    Change vs last month (sun ring) or distance from goal (ruler).

  8. 8

    FOOT

    Caption, then the closing SVG tag.

Build it in Qlik — step by step

  1. 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. 2

    Add a MetricMonth table: one row per metric and month, with the previous month’s value via Peek().

  3. 3

    For days metrics, build the ruler ticks and labels once in the load script (IterNo() loop + Concat) and join them to MetricMonth.

  4. 4

    Add the colour and helper variables.

  5. 5

    Add the 8 part variables and the final vGaugeSVG. The full script below contains steps 2–5.

  6. 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. 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.

'&#37;'

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 / N

Ruler 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 changeWhich variable
ColoursvG_TickOn, vG_TickOff, vG_Good, vG_Bad, …
Tick count for % / minutesvG_N (and vG_Dash for tick width)
Which metrics use the rulervG_Day (currently unit = days)
Ruler scaleGoal × 2, 10 ticks per unit (RulerTmp / RulerTicks)
Display namesvG_Name

Full script

Sun Gauge — Full load script

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.

About Robert Mika

Qlik developer sharing practical SVG techniques

Follow on LinkedIn