A horizontal bar chart ranking built with Bootstrap 6: a store's top 8 products with rank numbers, names, bars and values. A select switches the ranking between revenue, units sold and returns, and the rows glide into their new order. Use it as a leaderboard chart, a best sellers widget or a sorted bar chart on sales dashboards and admin panels.
How it works
The root .hbr-root holds a header with a Bootstrap 6 <select class="form-control">, a summary line, the .hbr-chart area and a footer note.
script.js reads the PRODUCTS array at the top of the file and builds one li.hbr-item per product inside the ol.hbr-list. Each row is a .hbr-row button with a .hbr-rank circle, the name and SKU, a .hbr-track with a .hbr-fill bar and the .hbr-value.
render() sorts the products by the selected metric, sets each bar width relative to the leader and colours it from the TINTS array (one indigo hue, darkest for rank 1). The rows are moved in the DOM, so reading order matches the visible order, and a FLIP animation slides them to their new place. The 30-day date range is computed from today.
Hovering, focusing or tapping a row shows the .hbr-tip tooltip with all three numbers for that product, including the return rate. A tap pins it (aria-expanded="true"); a second tap or Escape closes it.
Customization
PRODUCTSinscript.js: replace names, SKUs and therevenue,unitsandreturnsnumbers.METRICSinscript.js: rename a metric, change its number format, or add a new key together with an<option>in the select.TINTSinscript.js: a different colour ramp, for example teal or slate, from dark to light.--hbr-accent,--hbr-trackand--hbr-bginstyle.css: rank circle colour, empty track colour and page background.--hbr-row-gapon.hbr-root: more or less space between the bars.grid-template-columnsof.hbr-rowin the 768px media query: wider name or value columns.
Use cases
- E-commerce dashboards: best-selling products by revenue or units
- Quality and support reports: products with the most returns at the top
- Sales team leaderboards: reps ranked by deals or bookings
- Content analytics: top pages or articles by views
Accessibility
The ranking is an ordered list labelled by the heading, and every row is a button that contains the rank, name and value as text; the bars are aria-hidden. The tooltip is linked with aria-describedby. When the metric changes, a polite live region announces the new top three and the biggest climber. A visually hidden table lists all products with all three numbers. Focus outlines are visible, and the row animation is switched off with prefers-reduced-motion.
Bootstrap 6 notes
Built on Bootstrap 6.0.0-alpha.1 (alpha APIs can still change). Bootstrap 6 has no separate select class: the select uses form-control inside a form-field. The leader chip uses badge badge-subtle theme-primary instead of badge bg-primary. The root has data-bs-theme="light" so it stays light in dark mode. Icons come from Bootstrap Icons.