Skip to content

Stacked Bar Chart with Series Toggle

Stacked bar chart of weekly support tickets by status with a rescaling value axis, per-segment tooltips and checkbox chips that show or hide each series.

Also known as: stacked column chart, stacked bar graph, bar chart with legend filter, ticket status chart, css bar chart

Stacked Bar Chart with Series Toggle live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A stacked bar chart built with Tailwind CSS utilities and plain JavaScript, with no chart library and no canvas. This stacked column chart example shows weekly support tickets split into new, in progress and resolved, with a value axis, tooltips on every segment and checkbox chips that filter the series. Use it in helpdesk dashboards, admin panels and status reports.

How it works

The root section.sbc-root contains a header with three chips (label.sbc-chip wrapping a visually hidden checkbox with data-sbc-toggle), a row of figures and the chart. The chart is a small grid: [data-sbc-axis] holds the value labels, .sbc-plot holds the gridlines [data-sbc-grid], the bars [data-sbc-bars] and one shared tooltip [data-sbc-tip], and [data-sbc-labels] shows the weeks.

The script reads the DATA object at the top of script.js. It computes the Monday of each of the last eight weeks from today (shown as "Nov 3", or "11/3" on narrow screens, never with a year) and builds one .sbc-col per week with a .sbc-stack of button.sbc-seg elements. Each stack is as tall as its week total relative to the axis maximum, and each segment takes its share of the stack.

Hovering, tapping or focusing a segment marks it .is-active and places the tooltip next to it with the week, the status, the count and its share of the week. Unchecking a chip hides that status, recalculates the totals and the busiest week and rescales the axis; with motion allowed, the bars animate to their new height.

Customization

  • DATA.series in script.js: replace values with your weekly counts, or rename and recolor each status with name and color.
  • DATA.ticks: roughly how many gridlines the value axis gets (default 4).
  • DATA.unit: the word used in tooltips and announcements, for example orders or hours.
  • .sbc-plot height in style.css: 15rem on phones and 17rem from 640px.
  • max-w-12 on .sbc-stack (set in script.js): wider or slimmer bars.
  • The chip colors in style.css (.sbc-chip input[data-sbc-toggle="new"]:checked): keep them in sync with DATA.series[].color.

Use cases

  • Helpdesk and customer support dashboards: weekly ticket volume by status.
  • Project management tools: tasks opened, in review and done per sprint.
  • Operations reports: orders received, packed and shipped per week.

Accessibility

The chips are real checkboxes inside a fieldset with a hidden legend, so Space toggles them and the focus ring follows the checkbox. The bars group uses a roving tabindex: only one segment is in the tab order, Left and Right move between weeks, Up and Down between statuses, and Home and End jump to the first or last week. Each segment has an aria-label with the full value. A polite live region announces which series are shown and the new axis maximum, the last visible status cannot be hidden, and a visually hidden table lists every number. Reduced motion turns off the height animation.

Usage notes

The Inter font loads from Google Fonts. Every query is scoped to its .sbc-root, so several charts can share a page.

Stacked Bar Chart with Series Toggle at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS, fonts.googleapis.com
Layout
Responsive, works on mobile
Category
Charts
License
Free for personal and commercial use

Questions about this template

Can I use the Stacked Bar Chart with Series Toggle 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 Tailwind CSS and fonts.googleapis.com 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):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
  • <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap">

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Stacked Bar Chart with Series Toggle – free Tailwind CSS chart template
Stacked Bar Chart with Series Toggle · free Tailwind CSS chart template

More Charts

Funnel Chart – free Bootstrap 6 chart template

Funnel Chart

Sales funnel chart with five narrowing stages, user counts, step and overall conversion, a channel switch and a detail panel for the selected stage.

Revenue Area Chart Card – free Tailwind CSS chart template

Revenue Area Chart Card

Revenue area chart card with total revenue, change versus the previous period, a revenue and costs SVG area chart, legend toggles and a keyboard-friendly tooltip.

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

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.

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.