A sparkline KPI row in plain HTML, CSS and JavaScript: four stat tiles for revenue, orders, conversion rate and refunds, each with a value, a change badge and a small SVG line chart. A 7d / 30d / 90d segmented control swaps the data with no chart library, so this KPI dashboard example fits e-commerce admins, sales reports and analytics pages.
How it works
The root section.skr holds a header with the range text and a fieldset.skr-seg of native radio buttons styled as a segmented control. Each li.skr-tile has a data-skr-metric key, a .skr-value, a .skr-badge and a .skr-plot with one SVG (.skr-area, .skr-avg, .skr-line) plus an HTML dot and tooltip.
All numbers live in two objects at the top of script.js. PERIODS holds one series per metric for each range (7 daily, 30 daily or 13 weekly points) and the previous period's total. METRICS says whether a metric is summed or averaged, how it is formatted and which direction is good. On load and on every range change the script computes totals, changes and SVG paths and fills a visually hidden table with every data point. Values use Intl.NumberFormat; dates are counted back from today and shown without a year.
Moving the pointer over a sparkline, tapping it or focusing it shows a tooltip with the date and value of the nearest point. The dashed .skr-avg line marks the previous period's average per day or week.
Customization
PERIODSinscript.js: replace the arrays andprevioustotals with your own data; add a key such as'12m'and a matching radio input to get another range.goodWheninMETRICS: set to'down'for metrics where a fall is good (refunds, churn, bounce rate) so the badge and line turn green when they drop.kindinMETRICS:'currency','number'or'percent'; change thecurrency: 'USD'option of themoneyformatter for other currencies.--skr-goodand--skr-badon.skr: the emerald and red used for badges, lines and areas.--skr-plot-hon.skr: the height of every sparkline.
Use cases
- E-commerce admin dashboards: revenue, orders, conversion and refunds at a glance.
- SaaS analytics pages: MRR, sign-ups, trial conversion and churn with a range switch.
- Weekly sales reports: the 90-day view shows weekly totals with a clear trend line.
Accessibility
The range switch is a real radio group inside a fieldset with a legend, so arrow keys move between 7d, 30d and 90d. Each .skr-plot is focusable: Left/Right (or Up/Down), Home and End move through the data points, Escape hides the tooltip, and a polite live region reads the metric, date and value. Range changes are announced too. Badges include hidden "favorable" or "unfavorable" text so the meaning does not rely on color, and a visually hidden table repeats every number.
Usage notes
Radio names are set per instance, so several rows can share a page; give each copy a unique heading id.