Home / Part to Whole / Semi Donut Chart

Semi Donut Chart in HTML, CSS and JavaScript

A semi donut chart, or half donut, is a donut chart cut in half. This free template draws one with plain SVG and vanilla JavaScript, no chart library. The example shows a fundraising appeal and the money still needed.

Open live demoDownload HTML fileView code on GitHub
Semi Donut Chart made with HTML and JavaScript showing a fundraising appeal and the money still needed

What is a semi donut chart?

A semi donut chart, or half donut, is a donut chart cut in half. The ring runs from left to right over the top, which makes it look like a gauge and works well for progress toward a goal.

Each colored part shows how much one source added, and a gray part shows what is still missing. The big number in the middle tells the main story at a glance.

At a glance

Best for
Progress toward a goal, split by source
Data you need
A goal and an amount for each part
Skip it when
Data that is not a share of a fixed total.
Made with
HTML, CSS and vanilla JavaScript. No library.

When to use a semi donut chart

  • Fundraising and donation drives
  • Sales toward a monthly target
  • Storage or budget used against a limit
  • Seats filled in a hall or class

When to pick another chart

What you get in this template

How the code works

Here is a short version of the idea behind this semi donut chart. The full file adds the axis, labels, tooltips, sorting and resizing on top of it.

const goal = 50000;
const parts = [[18400, '#1d8a6f'], [11200, '#58b89b'], [7300, '#f2b33d']];
parts.push([goal - parts.reduce((a, p) => a + p[0], 0), '#dfe7e4']); // still needed
const cx = 200, cy = 200, r = 150, inner = 95;
const pt = (rad, a) => (cx + rad * Math.sin(a)) + ',' + (cy - rad * Math.cos(a));
let start = -Math.PI / 2; // 9 o clock

parts.forEach(([amount, color]) => {
  const end = start + amount / goal * Math.PI;
  make('path', { fill: color, d: 'M' + pt(r, start) + 'A' + r + ',' + r + ' 0 0 1 ' + pt(r, end) +
    'L' + pt(inner, end) + 'A' + inner + ',' + inner + ' 0 0 0 ' + pt(inner, start) + 'Z' });
  start = end;
});

The example uses four tiny helpers that create SVG shapes. Put them above the code and it runs as is.

const svg = document.querySelector('svg');
function make(tag, attrs) {
  const n = document.createElementNS('http://www.w3.org/2000/svg', tag);
  for (const k in attrs) n.setAttribute(k, attrs[k]);
  svg.appendChild(n);
  return n;
}
function drawRect(x, y, width, height, fill) { return make('rect', { x, y, width, height, fill }); }
function drawCircle(cx, cy, r, fill) { return make('circle', { cx, cy, r, fill }); }
function drawLine(x1, y1, x2, y2, stroke, width, dash) {
  return make('line', { x1, y1, x2, y2, stroke, 'stroke-width': width || 1, 'stroke-dasharray': dash || 'none' });
}
function drawText(x, y, str, anchor) {
  const t = make('text', { x, y, 'text-anchor': anchor || 'start' });
  t.textContent = str;
  return t;
}

How to add it to your website

  1. Download the file. Click Download HTML file above. You get one file called semi-donut-chart.html with everything inside.
  2. Change the data. Open the file in any code editor and find the DATA list near the bottom. Replace the names and numbers with your own.
  3. Change the colors and text. Colors are at the top of the style tag. The title, subtitle and main point are plain HTML near the top of the body.
  4. Put it online. Upload the file to any host, such as GitHub Pages, Netlify or your own server, or paste it into your site. There is no build step.

Questions people ask

What is a semi donut chart used for?

It is used for progress toward a goal, like money raised or sales against target, because the half ring reads like a gauge filling up.

How is a semi donut different from a gauge chart?

A gauge usually has one value and a needle. A semi donut can show several parts in different colors, so you can see where the progress came from.

How do I draw a half donut in SVG?

Use the same arc paths as a donut, but spread the angles over 180 degrees instead of 360, starting at 9 o clock and ending at 3 o clock.

Should I show the amount still needed?

Yes. A gray part for what is left makes the gap clear and turns the chart into a call to action.

More part to whole