webdevpuneet.com

ApexCharts Sparkline KPI Cards — Free Live Dashboard Snippet

ApexCharts Sparkline KPI Cards · Charts · Plain HTML, CSS & JS · Live preview

CategoryCharts

Copy & paste

Source Code

Requires
<div class="asp-wrap">
  <div class="asp-top">
    <div class="asp-title">Store overview</div>
    <div class="asp-live"><span class="asp-dot"></span>Live · updates every 2s</div>
  </div>
  <div class="asp-grid" id="aspGrid"></div>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

True sparklines
Axes, grid and padding removed with sparkline.enabled.
Mixed sparkline styles
Area, bar and line types per card.
Minimal tooltips
Value only, no labels or markers.
Good/bad colouring
goodUp decides green or red, not the arrow.
Rolling live window
Oldest point out, newest in, animated.
Window-based change
Badge compares the first and last visible points.
Auto-fit grid
Four, two or one column without media queries.
Reduced-motion aware
The live pulse stops for users who ask for less motion.

About this UI Snippet

ApexCharts Sparkline KPI Cards — Numbers With Their Trend Attached

Screenshot of the ApexCharts Sparkline KPI Cards snippet rendered live

A KPI number on its own hides the most important thing about it: which way it has been going. A sparkline — a tiny chart with no axes — puts the trend right under the number without taking over the card. This snippet builds a row of four KPI cards, each with a different sparkline style, updating live.

sparkline.enabled does the heavy lifting

Setting chart.sparkline.enabled: true removes axes, grid lines, the legend, the toolbar and chart padding in one go. The chart becomes a trend graphic that fills its container, which is exactly what a card needs. Everything else is regular ApexCharts, so each card can use a different type: a gradient area for revenue, bars for orders, and lines for rates.

Tooltips trimmed for small charts

The default tooltip shows the category and series name, which is noise on a 64px chart. The snippet hides the x value, the marker and the series title, leaving only the formatted value.

Colour by meaning, not direction

Each KPI carries a goodUp flag. Revenue going up is green; refund rate going up is red, even though its arrow also points up. This is the detail most dashboards get wrong — direction and desirability are different things.

A rolling window

Every two seconds each KPI drops its oldest point and appends a new one, then calls updateSeries. The change badge compares the newest value to the oldest in the window, so it always describes the visible trend.

Build the cards before the charts

A chart measures its container once, when it renders. If each card were added and charted in the same loop iteration, the first sparkline would render while it was the only card in an auto-fit grid — full row width — and keep that size after the other cards arrived. The snippet inserts all four cards first and creates the charts in a second pass.

Responsive grid

Cards sit in a repeat(auto-fit, minmax(210px, 1fr)) grid, so the row becomes two columns or one on narrow screens without media queries. The live-indicator pulse respects prefers-reduced-motion.

Step by step

How to Use

  1. 1
    Load ApexChartsInclude apexcharts.min.js from the CDN.
  2. 2
    Paste the snippetFour KPI cards render and start updating every two seconds.
  3. 3
    Hover a sparklineA compact tooltip shows only the value at that point.
  4. 4
    Read the badgesGreen means the move is good for that metric; red means it isn't.
  5. 5
    Define your KPIsEdit KPIS: label, colour, chart type, formatter and goodUp.
  6. 6
    Connect real dataReplace the setInterval simulation with your API or WebSocket.

Real-world uses

Common Use Cases

SaaS and store dashboards
Put a summary row of KPI cards above your detailed charts. Each shows the number, a change badge and a tiny trend line, so direction is visible without opening a report.
Admin panels at a glance
Surface traffic, signups and errors together. The goodUp flag colours a rise in errors red and a rise in signups green, so colour reflects whether a move is good, not just its direction.
Trading and crypto tiles
Show price tiles with recent movement. Area, bar and line sparkline styles can be mixed per card, so each metric gets the representation that suits it best.
Operations monitoring
Track latency, error rate and throughput in compact tiles. Sparkline tooltips show only the value, with no labels or markers cluttering a small card.
Reports and emails
Use the same tiny charts in exported reports, where a sparkline with no axes, grid or padding fits neatly beside a headline number.
Related: Sparkline Chart (vanilla)
A no-library version: Sparkline Chart.
Related: ApexCharts Mixed Bar and Line

Got questions?

Frequently Asked Questions

Set chart.sparkline.enabled to true. It hides axes, grid, legend and toolbar and removes padding, leaving a compact trend chart that fills its container. It works with line, area and bar types.

Set tooltip.x.show to false, tooltip.marker.show to false, and return an empty string from tooltip.y.title.formatter. Keep a y.formatter so the value is formatted in the right units.

Because an increase is bad for that metric. Each KPI has a goodUp flag, and the badge colour reflects whether the change is desirable, while the arrow still shows the direction.

Keep a fixed-length array per KPI. On each new value, drop the first element, push the new one, and call chart.updateSeries with the new data. ApexCharts animates the transition.

Each sparkline is a separate chart instance with its own SVG. A handful of cards is fine; for dozens of rows, lower the update frequency, disable animations, or draw simple SVG paths yourself.