Skip to content

Multi-Line Chart with Range Tabs

SVG multi-line chart comparing organic, paid and email traffic, with 7 day, 30 day and 12 month tabs, legend toggles and a crosshair tooltip.

Also known as: line chart with tooltip, traffic chart, analytics line graph, time series chart, comparison line chart

Multi-Line Chart with Range Tabs live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A multi-line chart built with Bootstrap 6 and inline SVG that compares website sessions from organic search, paid ads and email. Tabs switch between 7 days, 30 days and 12 months, the legend buttons show or hide each line, and a crosshair tooltip lists all values for one day. Use this line chart template as a traffic chart, an analytics line graph or a time series chart in dashboards and marketing reports.

How it works

The root .mlc-root holds a header with Bootstrap 6 nav nav-tabs, a .mlc-legend and the .mlc-plot with an empty svg.mlc-svg.

script.js starts with SERIES (key, label, colour) and DATA, which has one array per channel for 7d, 30d and 12m. The last value of each array is today or the current month; datesFor() counts backwards from today (no years shown).

draw() measures the plot width, picks a round tick step, and draws gridlines, axis labels, the "Sessions per day" unit and one path.mlc-line per visible channel. It redraws on resize.

Moving the pointer or touching the chart calls setActive(): a dashed crosshair and a dot per line move to the nearest point, and .mlc-tip lists the date and all visible values.

The legend buttons show each channel's total. Clicking one toggles aria-pressed and hides or shows its line; the last visible channel cannot be hidden.

Customization

  • DATA in script.js: paste your own arrays (any length) or fill it with fetch() before setRange() runs.
  • SERIES in script.js: rename channels, change the line colours or add a fourth channel with a matching array.
  • UNIT_LABEL and HEIGHT in script.js: the unit text above the y axis and the chart height on wide screens.
  • M in script.js: chart margins, for example more left space for long y labels.
  • --mlc-accent, --mlc-grid and --mlc-bg in style.css: active tab and focus colour, gridline colour and page background.
  • stroke-width in .mlc-line: thinner or bolder lines.

Use cases

  • Marketing dashboards: compare traffic from organic, paid and email campaigns
  • SaaS admin panels: sign-ups or active users per plan over time
  • Sales reports: revenue by region across days or months

Accessibility

The tabs follow the WAI-ARIA tabs pattern: role="tablist", aria-selected, roving tabindex, and Left/Right/Home/End move and select. The plot is focusable: Left and Right step through the points, Home and End jump to the ends, Escape hides the crosshair, and each step is announced through a polite live region. A visually hidden table lists every date with all three values and is rebuilt for each range. Legend toggles are buttons with aria-pressed, and channel names are always written next to their colour.

Bootstrap 6 notes

Built on Bootstrap 6.0.0-alpha.1 (alpha APIs can still change). The tabs reuse the nav nav-tabs look but are driven by script.js, because all ranges share one chart panel instead of separate .tab-panes. The root has data-bs-theme="light" so it stays light in dark mode.

Multi-Line Chart with Range Tabs at a glance

Framework
Bootstrap 6
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 6
Layout
Responsive, works on mobile
Category
Charts
License
Free for personal and commercial use

Questions about this template

Can I use the Multi-Line Chart with Range Tabs code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 6 from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css">
  • <script type="module" src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js"></script>

Built for Bootstrap 6.0.0-alpha.1. Bootstrap 6 ships as an ES module, so its script and this component's JavaScript load with type="module". Alpha releases can still change before the stable version.

Multi-Line Chart with Range Tabs – free Bootstrap 6 chart template
Multi-Line Chart with Range Tabs · free Bootstrap 6 chart template

More Charts

Sparkline KPI Row – free Pure CSS chart template

Sparkline KPI Row

Sparkline KPI row with four stat tiles, change badges and SVG sparklines that redraw when a 7d, 30d or 90d range is picked, with keyboard and touch tooltips.

SVG Line Chart with Hover Points – free Pure CSS chart template

SVG Line Chart with Hover Points

Smooth SVG line chart of daily website visitors with a gradient area fill, axis labels, and a crosshair tooltip that follows the pointer or the arrow keys.

Horizontal Bar Chart Ranking – free Bootstrap 6 chart template

Horizontal Bar Chart Ranking

Horizontal bar chart ranking the top 8 products by revenue, units or returns; a select re-sorts the bars and announces the new order.

Donut Chart with Legend – free Pure CSS chart template

Donut Chart with Legend

SVG donut chart of traffic sources with the total in the centre and an interactive legend that highlights each segment and shows its share, value and percent.

Pie Chart with Percentage Legend – free Bootstrap 6 chart template

Pie Chart with Percentage Legend

Budget pie chart with a percentage legend table: SVG slices drawn from a data array, and clicking a slice or category row pulls the slice out.

Bar Chart with Axis and Tooltips – free Pure CSS chart template

Bar Chart with Axis and Tooltips

Monthly sales bar chart with a labelled value axis, gridlines, tooltips on hover, focus and tap, and a this year / last year toggle that animates the bars.