ApexCharts Sparkline KPI Cards — Free Live Dashboard Snippet

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

CategoryCharts

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.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Paste this snippet into an AI assistant like Claude and ask it to explain what sparkline.enabled removes and why the badge colour depends on goodUp. You can then ask it to connect the cards to a WebSocket feed, add a comparison against the same period last week, or pause updates while the tab is hidden with the Page Visibility API. Ask it to review how the change percentage should behave when the first value in the window is zero.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a row of four live KPI cards with ApexCharts sparklines (loaded from a CDN) in plain HTML, CSS and JavaScript.

Requirements:
- KPIs: revenue (gradient area sparkline), orders (bar sparkline), conversion rate and refund rate (line sparklines), each with its own colour and number formatter.
- Enable ApexCharts sparkline mode so charts have no axes, grid or padding, and trim tooltips to show only the formatted value.
- Show the latest value and a change badge comparing the newest and oldest points in the window.
- Colour the badge green or red by whether the change is good for that metric (a rising refund rate is red), while the arrow shows direction.
- Every two seconds, drop each KPI's oldest point, append a new random-walk point and update the chart and badge.
- Lay cards out in an auto-fit CSS grid and add a pulsing live indicator that respects prefers-reduced-motion.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

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>

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
A summary row above detailed charts.
Admin panels
Traffic, signups and errors at a glance.
Trading and crypto UIs
Price tiles with recent movement.
Ops monitoring
Latency, error rate and throughput tiles.
Reports and emails
Static sparklines exported as images.
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.