webdevpuneet.com

ApexCharts Brush Chart with Range Navigator — Free Snippet

ApexCharts Brush Chart with Range Navigator · Charts · Plain HTML, CSS & JS · Live preview

CategoryCharts

About this UI Snippet

ApexCharts Brush Chart — Overview Below, Detail Above

Screenshot of the ApexCharts Brush Chart with Range Navigator snippet rendered live

Six months of daily data is too much to read at full resolution and too little to aggregate away. A brush chart solves this with two views of the same series: a small overview that always shows everything, and a larger detail chart that shows only the window selected in the overview. This is the pattern behind stock charts, analytics range pickers and log explorers.

Two charts, linked by id

The detail chart is created with chart.id: 'abr-main'. The overview enables chart.brush and sets target: 'abr-main'. That id is the only link between them — ApexCharts looks the target up in its own registry, so the two charts can live anywhere on the page.

The selection is the brush

The overview's chart.selection sets the initial window (the last 60 days here) and styles the draggable highlight. Dragging moves it; dragging its edges resizes it. Each change updates the detail chart's visible x-range.

autoScaleYaxis matters more than it looks

Without autoScaleYaxis: true, the detail chart keeps the y-range of the full dataset. When you zoom into a quiet period, the line hugs the middle of the chart and variation disappears. With it enabled, the y-axis is re-fitted to the data inside the window.

Reacting to the window

The detail chart's events.zoomed callback receives the new xaxis.min and xaxis.max. The snippet uses them to compute the average of the visible points, a small example of keeping other UI in sync with the brush.

Rendering order

The overview is rendered after the detail chart resolves its render() promise, so the target already exists when the brush tries to control it.

Synthetic data with a real shape

The data generator uses a seeded random function, a slow trend and a weekend dip, so the chart looks like a real product metric and renders identically every time.

What's included

Features

Linked brush and target
The overview controls the detail chart through chart.id.
Draggable, resizable window
A styled selection sets the visible range.
Auto-scaling y-axis
autoScaleYaxis keeps variation visible when zoomed in.
Datetime axis
Real timestamps with formatted tooltips.
Live summary stat
The zoomed event keeps a header average in sync.
Deterministic sample data
A seeded generator renders identically every load.
Gradient area fill
The detail chart fades from the line to the baseline.
Minimal overview
No grid, labels or tooltip, so it reads as a control.

Step by step

How to Use

  1. 1
    Load ApexChartsInclude apexcharts.min.js from the CDN.
  2. 2
    Paste the snippetA detail area chart renders above a compact overview chart.
  3. 3
    Drag the windowMove the shaded selection in the overview to pan the detail chart.
  4. 4
    Resize the windowDrag its edges to zoom in or out; the y-axis rescales to fit.
  5. 5
    Watch the averageThe figure in the header recalculates for the visible range.
  6. 6
    Use your dataReplace the generated [timestamp, value] pairs with your own series.

Real-world uses

Common Use Cases

Product analytics exploration
Explore months of active-user or signup data by dragging a window across a small overview, while the detail chart above zooms to match the selection.
Finance and trading interfaces
Provide the standard overview-plus-detail layout, with autoScaleYaxis keeping variation visible when the view is zoomed into a narrow slice.
Monitoring incident windows
Zoom into an incident window inside weeks of metrics without losing the surrounding context, and read the live average of the visible range.
IoT and sensor time series
Navigate dense readings without downsampling them first. The datetime axis keeps real timestamps in the formatted tooltips as you zoom.
Learning linked ApexCharts
See how the overview controls the detail chart through chart.id, and how a styled, draggable selection window sets the visible range.
Related: ECharts Revenue Line with Zoom Brush
The same idea built with ECharts dataZoom: ECharts Animated Revenue Line with Zoom Brush.
Related: ApexCharts Annotations

Got questions?

Frequently Asked Questions

Two charts render the same series. The detail chart gets a chart.id; the overview chart enables chart.brush with target set to that id, and enables chart.selection to draw a draggable window. Moving or resizing the window sets the detail chart's visible x-range.

It recalculates the detail chart's y-axis from the points inside the selected window. Without it, the y-axis stays scaled to the whole dataset, so zooming into a narrow range shows a nearly flat line.

Listen to the target chart's zoomed event (or the brush chart's brushScrolled or selection events). The callback receives an object with xaxis.min and xaxis.max as timestamps, which you can use to filter data or update other components.

The brush looks up its target chart by id. Rendering the target first, and only then the brush, guarantees the target exists when the brush applies its initial selection.

Yes. Render two Chart components with the same series. Give the first options.chart.id and the second options.chart.brush.target set to that id, plus a selection range. The linking works the same way because it is based on ids, not DOM elements.

Copy & paste

Source Code

Requires
<div class="abr-wrap">
  <div class="abr-card">
    <div class="abr-head">
      <div>
        <div class="abr-title">Daily Active Users</div>
        <div class="abr-sub">Drag or resize the highlighted window in the lower chart to zoom the upper one</div>
      </div>
      <div class="abr-stat"><span id="abrAvg">—</span><small>avg in view</small></div>
    </div>
    <div id="abrMain"></div>
    <div id="abrBrush"></div>
  </div>
</div>

Extend with AI

Take This Snippet Further With AI

Give this snippet to an AI assistant like Claude and ask it to walk through how the brush chart finds its target, and why autoScaleYaxis changes what you can see when zoomed in. It can help you extend the pattern: preset buttons (7D, 30D, 90D) that set the brush selection programmatically, a second series such as signups on the detail chart only, or URL parameters that restore a shared range. Ask it how to keep the overview readable when the series has tens of thousands of points.

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 an overview-plus-detail brush chart with ApexCharts (loaded from a CDN) in plain HTML, CSS and JavaScript.

Requirements:
- Generate 180 days of daily values with a slow upward trend, a weekend dip and deterministic seeded noise, stored as [timestamp, value] pairs on a datetime x-axis.
- Render a detail area chart with a gradient fill, smooth line, formatted date tooltips and a y-axis in thousands.
- Render a compact overview chart below it that acts as a brush targeting the detail chart by id, with a styled draggable and resizable selection initially covering the last 60 days.
- Re-fit the detail chart's y-axis to the data inside the selected window.
- Show the average value of the currently visible range in the card header and update it whenever the window changes.
- Hide grid lines, y-axis labels and tooltips on the overview so it reads as a control rather than a second chart.

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.