A budget pie chart built with Bootstrap 6 and plain SVG: six spending categories, a legend table with amount and percent, and a slice that pulls out when you pick it. Use this pie chart template as an expense breakdown, a budget planner widget or a percentage chart in finance apps and reports.
How it works
The root .bpc-root holds a Bootstrap 6 .card with a header, a figure with the pie and a .bpc-legend table. script.js reads the BUDGET array, draws one SVG path per item inside .bpc-slices (percent labels on slices of 6% or more) and builds a table row with a .bpc-toggle button, the amount (Intl.NumberFormat), the share and a small share bar. Percentages use the largest remainder method, so they always add up to exactly 100%.
Clicking a slice or a row calls select(): the slice gets .is-active and moves out along its middle angle (PULL), the others get .is-dim, and the row button gets aria-pressed="true". The .bpc-detail pill shows the category, amount and share. Clicking again or pressing Escape puts the slice back. Hovering a slice or row, or focusing a row button, shows the .bpc-tip tooltip. On load the largest category is pulled out.
Customization
BUDGETinscript.js: replace the labels, amounts andcolorvalues; the pie, table and total update on their own.CURRENCYinscript.js: switch toEUR,GBPor any ISO code for every amount.PULLandRADIUSinscript.js: how far the selected slice moves out and how large the pie is.--bpc-pie-sizeon.bpc-root: the pie width and the left column width on wide screens.--bpc-bg,--bpc-card,--bpc-lineand--bpc-activeinstyle.css: page background, card surface, table lines and the selected row tint.- Remove the
.bpc-barspan inscript.jsto show only the percent number in the Share column.
Use cases
- Personal finance apps: show how a monthly budget is split across categories
- Accounting and expense dashboards: compare cost centres by share of the total
- Survey and poll results: show answer shares with exact percentages
Accessibility
The SVG has role="img" and a title that lists every category with its percent; the slices are hidden from screen readers. The legend is a real table with a hidden caption and a total row, so the same numbers are available as text. Every category is a native button with aria-pressed, operated with Tab, Enter or Space; focus shows the tooltip and an outline. The detail pill is an aria-live="polite" region, so each selection is announced. Names and percents are always written out, so color is never the only cue. Slice movement uses a short transition that is switched off with prefers-reduced-motion.
Bootstrap 6 notes
Built on Bootstrap 6.0.0-alpha.1 (alpha APIs can still change). It uses .card and .table, with --bs-table-bg and --bs-card-bg set on the component. The root has data-bs-theme="light", so it keeps its light look when the visitor uses dark mode. Icons come from Bootstrap Icons.