Skip to content
OpenChart

Pie chart vs bar chart vs waffle chart

A pie works for one dominant share, bars for close values, and a waffle for one percentage you want counted. Examples use US debt and federal spending.

MortgagesAll other debtMortgages are 70% of US household debtShare of $18.8 trillion in US household debt, fourth quarter of 2025MortgagesAll other debtMortgages are 70% of US household debtShare of $18.8 trillion in US household debt, fourth quarter of 2025
US household debt, mortgages and all other debt, as a donut. Source: Federal Reserve Bank of New York, Household Debt and Credit Report.

Made with OpenChart. How to build this pie chart

Mortgages make up 70% of what US households owe, and a pie shows that faster than a table, because one slice takes most of the circle. The rest of the debt is harder to show. Car loans, student loans and credit cards sit within $0.4 trillion of each other, and slice angles can’t rank them.

Pie and donut charts

A pie works for two or three parts of a true whole, best when one part dominates. Its slices must add up to 100%, so it is the wrong chart for survey answers where people could pick several options. This one has two slices, mortgages and everything else, and it is drawn as a donut, a pie with a hole that holds the share.

MortgagesAll other debtMortgages are 70% of US household debtShare of $18.8 trillion in US household debt, fourth quarter of 2025MortgagesAll other debtMortgages are 70% of US household debtShare of $18.8 trillion in US household debt, fourth quarter of 2025
US household debt, mortgages and all other debt, as a donut. Source: Federal Reserve Bank of New York, Household Debt and Credit Report.

Made with OpenChart. How to build this pie chart

{
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "70%",
      "subtitle": "mortgages"
    }
  },
  "data": [
    {
      "type": "Mortgages",
      "balance": 13.17
    },
    {
      "type": "All other debt",
      "balance": 5.61
    }
  ],
  "encoding": {
    "theta": {
      "field": "balance",
      "type": "quantitative"
    },
    "color": {
      "field": "type",
      "type": "nominal",
      "scale": {
        "domain": [
          "Mortgages",
          "All other debt"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "legend": {
    "position": "bottom"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "chrome": {
    "title": "Mortgages are 70% of US household debt",
    "subtitle": "Share of $18.8 trillion in US household debt, fourth quarter of 2025"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "70%",
      "subtitle": "mortgages"
    }
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "balance",
      "type": "quantitative"
    },
    "color": {
      "field": "type",
      "type": "nominal",
      "scale": {
        "domain": [
          "Mortgages",
          "All other debt"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "legend": {
    "position": "bottom"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "chrome": {
    "title": "Mortgages are 70% of US household debt",
    "subtitle": "Share of $18.8 trillion in US household debt, fourth quarter of 2025"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "70%",
      "subtitle": "mortgages"
    }
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "balance",
      "type": "quantitative"
    },
    "color": {
      "field": "type",
      "type": "nominal",
      "scale": {
        "domain": [
          "Mortgages",
          "All other debt"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "legend": {
    "position": "bottom"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "chrome": {
    "title": "Mortgages are 70% of US household debt",
    "subtitle": "Share of $18.8 trillion in US household debt, fourth quarter of 2025"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "70%",
      "subtitle": "mortgages"
    }
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "balance",
      "type": "quantitative"
    },
    "color": {
      "field": "type",
      "type": "nominal",
      "scale": {
        "domain": [
          "Mortgages",
          "All other debt"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "legend": {
    "position": "bottom"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "chrome": {
    "title": "Mortgages are 70% of US household debt",
    "subtitle": "Share of $18.8 trillion in US household debt, fourth quarter of 2025"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": {
    "type": "arc",
    "innerRadius": 0.6,
    "centerLabel": {
      "text": "70%",
      "subtitle": "mortgages"
    }
  },
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "balance",
      "type": "quantitative"
    },
    "color": {
      "field": "type",
      "type": "nominal",
      "scale": {
        "domain": [
          "Mortgages",
          "All other debt"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "legend": {
    "position": "bottom"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "chrome": {
    "title": "Mortgages are 70% of US household debt",
    "subtitle": "Share of $18.8 trillion in US household debt, fourth quarter of 2025"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Bar charts for close values

Split the same debt five ways and a pie stops helping. Sorted bars put every value on one baseline, so the order is plain. Student loans lead credit cards by $0.39 trillion, a few degrees of difference on a pie and a clear step between two bars.

Some gaps are too small even for bars. Auto loans ($1.667 trillion) and student loans ($1.664 trillion) differ by about $3 billion, so their bars look the same length, and the printed values carry that comparison. Home equity loans (2.3% of the total) and the New York Fed’s own “other” category (3.0%) are merged into one “Other” row.

02468101214$ trillionsMortgageAutoStudentCardsOther13.171.671.661.281.00Student loan debt exceeds credit card debt by $0.39 trillionUS household debt by type, fourth quarter of 2025, $ trillions02468101214$ trillionsMortgageAutoStudentCardsOther13.171.671.661.281.00Student loan debt exceeds credit card debt by $0.39 trillionUS household debt by type, fourth quarter of 2025, $ trillions
Live example. Source: Federal Reserve Bank of New York, Household Debt and Credit Report.

Made with OpenChart. How to build this bar chart

{
  "mark": "bar",
  "data": [
    {
      "type": "Mortgage",
      "balance": 13.17
    },
    {
      "type": "Auto",
      "balance": 1.67
    },
    {
      "type": "Student",
      "balance": 1.66
    },
    {
      "type": "Cards",
      "balance": 1.28
    },
    {
      "type": "Other",
      "balance": 1
    }
  ],
  "encoding": {
    "x": {
      "field": "balance",
      "type": "quantitative",
      "axis": {
        "title": "$ trillions",
        "format": ".0f"
      }
    },
    "y": {
      "field": "type",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ".2f"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Student loan debt exceeds credit card debt by $0.39 trillion",
    "subtitle": "US household debt by type, fourth quarter of 2025, $ trillions"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "bar",
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "balance",
      "type": "quantitative",
      "axis": {
        "title": "$ trillions",
        "format": ".0f"
      }
    },
    "y": {
      "field": "type",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ".2f"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Student loan debt exceeds credit card debt by $0.39 trillion",
    "subtitle": "US household debt by type, fourth quarter of 2025, $ trillions"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "bar",
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "balance",
      "type": "quantitative",
      "axis": {
        "title": "$ trillions",
        "format": ".0f"
      }
    },
    "y": {
      "field": "type",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ".2f"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Student loan debt exceeds credit card debt by $0.39 trillion",
    "subtitle": "US household debt by type, fourth quarter of 2025, $ trillions"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "bar",
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "balance",
      "type": "quantitative",
      "axis": {
        "title": "$ trillions",
        "format": ".0f"
      }
    },
    "y": {
      "field": "type",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ".2f"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Student loan debt exceeds credit card debt by $0.39 trillion",
    "subtitle": "US household debt by type, fourth quarter of 2025, $ trillions"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "bar",
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "balance",
      "type": "quantitative",
      "axis": {
        "title": "$ trillions",
        "format": ".0f"
      }
    },
    "y": {
      "field": "type",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ".2f"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Student loan debt exceeds credit card debt by $0.39 trillion",
    "subtitle": "US household debt by type, fourth quarter of 2025, $ trillions"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Sort the bars by value unless the categories have a natural order, such as age bands or months. Bars don’t need the parts to add up to a whole, so they also work for values that are not shares. Use them whenever the reader has to compare parts with each other, or when there are more than five or six parts. The bar chart page covers the options.

Waffle charts

A waffle draws 100 squares, one for each percent. It suits a single share you want the reader to feel as a count rather than read as an angle, since counting 66 squares is easier than judging a slice that spans 238 degrees.

In fiscal 2024, payments for individuals took 66 of every 100 federal dollars. That is the Office of Management and Budget’s category for money paid to people or spent on their behalf, such as Social Security, Medicare and Medicaid.

Payments for individualsAll other outlaysPayments for individuals were 66% of federal spending in 2024Share of US federal outlays by category, fiscal year 2024. Each square is one percent.Payments for individualsAll other outlaysPayments for individuals were 66% of federal spending in 2024Share of US federal outlays by category, fiscal year 2024. Each square is one percent.
Federal outlays in the latest year as a waffle. Source: US Office of Management and Budget, Historical Tables (Table 6.1, composition of outlays).

Made with OpenChart. How to build this waffle chart

{
  "mark": "waffle",
  "data": [
    {
      "category": "Payments for individuals",
      "share": 66
    },
    {
      "category": "All other outlays",
      "share": 34
    }
  ],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "highlight": "Payments for individuals"
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Payments for individuals were 66% of federal spending in 2024",
    "subtitle": "Share of US federal outlays by category, fiscal year 2024. Each square is one percent."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "waffle",
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "highlight": "Payments for individuals"
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Payments for individuals were 66% of federal spending in 2024",
    "subtitle": "Share of US federal outlays by category, fiscal year 2024. Each square is one percent."
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "waffle",
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "highlight": "Payments for individuals"
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Payments for individuals were 66% of federal spending in 2024",
    "subtitle": "Share of US federal outlays by category, fiscal year 2024. Each square is one percent."
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "waffle",
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "highlight": "Payments for individuals"
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Payments for individuals were 66% of federal spending in 2024",
    "subtitle": "Share of US federal outlays by category, fiscal year 2024. Each square is one percent."
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "waffle",
  "data": [/* 2 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "theta": {
      "field": "share",
      "type": "quantitative"
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "highlight": "Payments for individuals"
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Payments for individuals were 66% of federal spending in 2024",
    "subtitle": "Share of US federal outlays by category, fiscal year 2024. Each square is one percent."
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

A waffle rounds to whole squares and carries few categories, so it is a poor tool for comparing close values. Keep it to one share and highlight it.

Shares over time

A pie per year would ask the reader to compare angles across dozens of circles. A 100% stacked area chart scales every year to the same height and shows how the mix shifts. Defense took 49.0% of federal outlays in 1962 and 13.0% in 2024, while payments for individuals went from 27.5% to 66.0%.

1970198019902000201020200%20%40%60%80%100%Share of outlaysPayments for individualsNational defenseNet interestEverything elsePayments for individuals passed defense in 1971 and reached 66% by2024Share of US federal outlays by category, fiscal years 1962 to 20241970198019902000201020200%20%40%60%80%100%Share of outlaysPayments for individualsNational defenseNet interestEverything elsePayments for individuals passed defense in 1971 and reached 66% by2024Share of US federal outlays by category, fiscal years 1962 to 2024
Live example. Source: US Office of Management and Budget, Historical Tables (Table 6.1, composition of outlays).

Made with OpenChart. How to build this area chart

{
  "mark": {
    "type": "area",
    "interpolate": "linear"
  },
  "data": [
    {
      "date": "1962-01-01",
      "category": "Payments for individuals",
      "share": 27.5
    },
    {
      "date": "1962-01-01",
      "category": "National defense",
      "share": 49
    },
    {
      "date": "1962-01-01",
      "category": "Net interest",
      "share": 6.4
    },
    {
      "date": "1962-01-01",
      "category": "Everything else",
      "share": 17
    },
    {
      "date": "1963-01-01",
      "category": "Payments for individuals",
      "share": 28.4
    },
    {
      "date": "1963-01-01",
      "category": "National defense",
      "share": 48
    },
    // … 246 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%Y",
        "tickCount": 6
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of outlays",
        "format": ".0%",
        "grid": true
      }
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "scale": {
        "domain": [
          "Payments for individuals",
          "National defense",
          "Net interest",
          "Everything else"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        },
        {
          "light": "#7c3aed",
          "dark": "#a78bfa"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "legend": {
    "position": "top"
  },
  "chrome": {
    "title": "Payments for individuals passed defense in 1971 and reached 66% by 2024",
    "subtitle": "Share of US federal outlays by category, fiscal years 1962 to 2024"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 252 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%Y",
        "tickCount": 6
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of outlays",
        "format": ".0%",
        "grid": true
      }
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "scale": {
        "domain": [
          "Payments for individuals",
          "National defense",
          "Net interest",
          "Everything else"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        },
        {
          "light": "#7c3aed",
          "dark": "#a78bfa"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "legend": {
    "position": "top"
  },
  "chrome": {
    "title": "Payments for individuals passed defense in 1971 and reached 66% by 2024",
    "subtitle": "Share of US federal outlays by category, fiscal years 1962 to 2024"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 252 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%Y",
        "tickCount": 6
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of outlays",
        "format": ".0%",
        "grid": true
      }
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "scale": {
        "domain": [
          "Payments for individuals",
          "National defense",
          "Net interest",
          "Everything else"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        },
        {
          "light": "#7c3aed",
          "dark": "#a78bfa"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "legend": {
    "position": "top"
  },
  "chrome": {
    "title": "Payments for individuals passed defense in 1971 and reached 66% by 2024",
    "subtitle": "Share of US federal outlays by category, fiscal years 1962 to 2024"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 252 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%Y",
        "tickCount": 6
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of outlays",
        "format": ".0%",
        "grid": true
      }
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "scale": {
        "domain": [
          "Payments for individuals",
          "National defense",
          "Net interest",
          "Everything else"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        },
        {
          "light": "#7c3aed",
          "dark": "#a78bfa"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "legend": {
    "position": "top"
  },
  "chrome": {
    "title": "Payments for individuals passed defense in 1971 and reached 66% by 2024",
    "subtitle": "Share of US federal outlays by category, fiscal years 1962 to 2024"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 252 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "area",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%Y",
        "tickCount": 6
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "stack": "normalize",
      "axis": {
        "title": "Share of outlays",
        "format": ".0%",
        "grid": true
      }
    },
    "color": {
      "field": "category",
      "type": "nominal",
      "scale": {
        "domain": [
          "Payments for individuals",
          "National defense",
          "Net interest",
          "Everything else"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        },
        {
          "light": "#7c3aed",
          "dark": "#a78bfa"
        },
        {
          "light": "#9ca3af",
          "dark": "#6b7280"
        }
      ]
    }
  },
  "legend": {
    "position": "top"
  },
  "chrome": {
    "title": "Payments for individuals passed defense in 1971 and reached 66% by 2024",
    "subtitle": "Share of US federal outlays by category, fiscal years 1962 to 2024"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Normalizing hides the total, so state the dollars elsewhere if they matter. “Everything else” here is the total minus the three named categories. It holds grants, other nondefense spending and offsetting receipts, which are fees and other money agencies collect and net against their spending, so they count as negative outlays. Only the bottom band sits on a flat baseline, so label the values you want read.

The spec

The donut is mark: { type: "arc", innerRadius: 0.6 } with the number on theta and the category on color, and centerLabel prints the share in the hole. A waffle is mark: "waffle" with the same two channels, and highlight on color keeps one category in color and mutes the rest.

The bar chart puts the number on x and the category on y, with sort: "-x" to put the longest bar first and labels.format to print each value. The area chart sets stack: "normalize" on y and prints the axis as a percentage with format: ".0%". Each chart lists its colors as { light, dark } pairs in theme.colors.categorical, so a value printed in the bar color stays readable on a dark page. The 100% stacked page and the waffle page cover the stacking and highlight options.

The pie and donut page shows how slices under about 3% of a total fold into one “Other” slice.