Skip to content
OpenChart

How to build a KPI dashboard with sparklines

A KPI tile is a number, a comparison and a small line. This post builds a row of them and covers what to label once the sparkline has no axes.

Mortgage rate, weekly: 7.11%Mortgage rate, weekly: 7.11%
A sparkline of the 30-year mortgage rate. Source: Freddie Mac, 30-Year Fixed Rate Mortgage Average (via FRED MORTGAGE30US).

Made with OpenChart. How to build this line chart

In the latest readings, the 30-year mortgage rate is 0.87 points above a year earlier, a dozen eggs cost $1.17 less than about a year before, and the share of US job postings that mention remote or hybrid work is up 0.40 points. A KPI dashboard should make answers like those readable in a few seconds. Each number gets a tile with three parts: the latest reading, a comparison and a small line for the shape.

Mortgage rate, weekly, %Eggs, a dozen, monthly, $Remote job ads, quarterly, %Three KPIs, January 2021 to latestLatest reading over each panel, with its change from a year earlier. Each line has its own scale.VS NOV 13, 2025: 6.24%7.11%+0.87 ptsVS SEP 2025: $3.49$2.32−$1.17VS 2025-Q3: 8.18%8.58%+0.40 ptsMortgage rate, weekly, %Eggs, a dozen, monthly, $Remote job ads, quarterly, %Three KPIs, January 2021 to latestLatest reading over each panel, with its change from a year earlier. Each line has its own scale.VS NOV 13, 2025: 6.24%7.11%+0.87 ptsVS SEP 2025: $3.49$2.32−$1.17VS 2025-Q3: 8.18%8.58%+0.40 pts
Three KPI tiles for the mortgage rate, egg prices and remote job ads. Source: Freddie Mac, 30-Year Fixed Rate Mortgage Average (via FRED MORTGAGE30US); US Bureau of Labor Statistics, Average Price Data (eggs, grade A, large); Indeed Hiring Lab, Remote and Hybrid Job Postings Tracker.

Made with OpenChart. How to build this line chart

{
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "interpolate": "linear"
  },
  "data": [
    {
      "tile": "Mortgage rate, weekly, %",
      "date": "2021-01-07",
      "value": 2.65
    },
    {
      "tile": "Mortgage rate, weekly, %",
      "date": "2021-01-14",
      "value": 2.79
    },
    {
      "tile": "Mortgage rate, weekly, %",
      "date": "2021-01-21",
      "value": 2.77
    },
    {
      "tile": "Mortgage rate, weekly, %",
      "date": "2021-01-28",
      "value": 2.73
    },
    {
      "tile": "Mortgage rate, weekly, %",
      "date": "2021-02-04",
      "value": 2.73
    },
    {
      "tile": "Mortgage rate, weekly, %",
      "date": "2021-02-11",
      "value": 2.73
    },
    // … 393 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "facet": {
      "field": "tile",
      "type": "nominal",
      "sort": null,
      "columns": 3
    }
  },
  "resolve": {
    "scale": {
      "y": "independent"
    }
  },
  "metrics": [
    {
      "label": "vs Nov 13, 2025: 6.24%",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "vs Sep 2025: $3.49",
      "value": "$2.32",
      "delta": "−$1.17",
      "deltaTone": "down"
    },
    {
      "label": "vs 2025-Q3: 8.18%",
      "value": "8.58%",
      "delta": "+0.40 pts",
      "deltaTone": "up"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "Three KPIs since 2021",
        "subtitle": "Latest, and change from a year earlier: mortgage rate 7.11% (+0.87 pts), eggs $2.32 (−$1.17), remote job ads 8.58% (+0.40 pts)."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    },
    "spacing": {
      "padding": 4
    }
  },
  "chrome": {
    "title": "Three KPIs, January 2021 to latest",
    "subtitle": "Latest reading over each panel, with its change from a year earlier. Each line has its own scale."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "facet": {
      "field": "tile",
      "type": "nominal",
      "sort": null,
      "columns": 3
    }
  },
  "resolve": {
    "scale": {
      "y": "independent"
    }
  },
  "metrics": [
    {
      "label": "vs Nov 13, 2025: 6.24%",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "vs Sep 2025: $3.49",
      "value": "$2.32",
      "delta": "−$1.17",
      "deltaTone": "down"
    },
    {
      "label": "vs 2025-Q3: 8.18%",
      "value": "8.58%",
      "delta": "+0.40 pts",
      "deltaTone": "up"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "Three KPIs since 2021",
        "subtitle": "Latest, and change from a year earlier: mortgage rate 7.11% (+0.87 pts), eggs $2.32 (−$1.17), remote job ads 8.58% (+0.40 pts)."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    },
    "spacing": {
      "padding": 4
    }
  },
  "chrome": {
    "title": "Three KPIs, January 2021 to latest",
    "subtitle": "Latest reading over each panel, with its change from a year earlier. Each line has its own scale."
  }
};

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 = [/* 399 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "facet": {
      "field": "tile",
      "type": "nominal",
      "sort": null,
      "columns": 3
    }
  },
  "resolve": {
    "scale": {
      "y": "independent"
    }
  },
  "metrics": [
    {
      "label": "vs Nov 13, 2025: 6.24%",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "vs Sep 2025: $3.49",
      "value": "$2.32",
      "delta": "−$1.17",
      "deltaTone": "down"
    },
    {
      "label": "vs 2025-Q3: 8.18%",
      "value": "8.58%",
      "delta": "+0.40 pts",
      "deltaTone": "up"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "Three KPIs since 2021",
        "subtitle": "Latest, and change from a year earlier: mortgage rate 7.11% (+0.87 pts), eggs $2.32 (−$1.17), remote job ads 8.58% (+0.40 pts)."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    },
    "spacing": {
      "padding": 4
    }
  },
  "chrome": {
    "title": "Three KPIs, January 2021 to latest",
    "subtitle": "Latest reading over each panel, with its change from a year earlier. Each line has its own scale."
  }
};
</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 = [/* 399 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "facet": {
      "field": "tile",
      "type": "nominal",
      "sort": null,
      "columns": 3
    }
  },
  "resolve": {
    "scale": {
      "y": "independent"
    }
  },
  "metrics": [
    {
      "label": "vs Nov 13, 2025: 6.24%",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "vs Sep 2025: $3.49",
      "value": "$2.32",
      "delta": "−$1.17",
      "deltaTone": "down"
    },
    {
      "label": "vs 2025-Q3: 8.18%",
      "value": "8.58%",
      "delta": "+0.40 pts",
      "deltaTone": "up"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "Three KPIs since 2021",
        "subtitle": "Latest, and change from a year earlier: mortgage rate 7.11% (+0.87 pts), eggs $2.32 (−$1.17), remote job ads 8.58% (+0.40 pts)."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    },
    "spacing": {
      "padding": 4
    }
  },
  "chrome": {
    "title": "Three KPIs, January 2021 to latest",
    "subtitle": "Latest reading over each panel, with its change from a year earlier. Each line has its own scale."
  }
};
</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 = [/* 399 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "facet": {
      "field": "tile",
      "type": "nominal",
      "sort": null,
      "columns": 3
    }
  },
  "resolve": {
    "scale": {
      "y": "independent"
    }
  },
  "metrics": [
    {
      "label": "vs Nov 13, 2025: 6.24%",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "vs Sep 2025: $3.49",
      "value": "$2.32",
      "delta": "−$1.17",
      "deltaTone": "down"
    },
    {
      "label": "vs 2025-Q3: 8.18%",
      "value": "8.58%",
      "delta": "+0.40 pts",
      "deltaTone": "up"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "Three KPIs since 2021",
        "subtitle": "Latest, and change from a year earlier: mortgage rate 7.11% (+0.87 pts), eggs $2.32 (−$1.17), remote job ads 8.58% (+0.40 pts)."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    },
    "spacing": {
      "padding": 4
    }
  },
  "chrome": {
    "title": "Three KPIs, January 2021 to latest",
    "subtitle": "Latest reading over each panel, with its change from a year earlier. Each line has its own scale."
  }
};

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

What goes in a KPI tile

A number alone does not say whether it is high, so every tile needs a comparison. Pick the one the reader acts on: the previous period for numbers that move week to week, the same period a year earlier for anything with a season, or a target when there is one. These tiles use a year earlier, which also cancels any seasonal swing.

30-year fixed mortgage rate, weekly, %LATEST, NOV 12, 20267.11%+0.87 ptsA YEAR EARLIER, NOV 13, 20256.24%PEAK, OCT 26, 20237.79%30-year fixed mortgage rate, weekly, %LATEST, NOV 12, 20267.11%+0.87 ptsA YEAR EARLIER, NOV 13, 20256.24%PEAK, OCT 26, 20237.79%
Live example. Source: Freddie Mac, 30-Year Fixed Rate Mortgage Average (via FRED MORTGAGE30US).

Made with OpenChart. How to build this line chart

{
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "point": "last",
    "interpolate": "linear"
  },
  "data": [
    {
      "date": "2021-01-07",
      "value": 2.65
    },
    {
      "date": "2021-01-14",
      "value": 2.79
    },
    {
      "date": "2021-01-21",
      "value": 2.77
    },
    {
      "date": "2021-01-28",
      "value": 2.73
    },
    {
      "date": "2021-02-04",
      "value": 2.73
    },
    {
      "date": "2021-02-11",
      "value": 2.73
    },
    // … 300 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    }
  },
  "metrics": [
    {
      "label": "Latest, Nov 12, 2026",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "A year earlier, Nov 13, 2025",
      "value": "6.24%"
    },
    {
      "label": "Peak, Oct 26, 2023",
      "value": "7.79%"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "30-year mortgage rate, weekly: 7.11%",
        "subtitle": "+0.87 pts from a year earlier (6.24% on Nov 13, 2025). Peak, Oct 26, 2023: 7.79%."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "30-year fixed mortgage rate, weekly, %"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "point": "last",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    }
  },
  "metrics": [
    {
      "label": "Latest, Nov 12, 2026",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "A year earlier, Nov 13, 2025",
      "value": "6.24%"
    },
    {
      "label": "Peak, Oct 26, 2023",
      "value": "7.79%"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "30-year mortgage rate, weekly: 7.11%",
        "subtitle": "+0.87 pts from a year earlier (6.24% on Nov 13, 2025). Peak, Oct 26, 2023: 7.79%."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "30-year fixed mortgage rate, weekly, %"
  }
};

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 = [/* 306 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "point": "last",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    }
  },
  "metrics": [
    {
      "label": "Latest, Nov 12, 2026",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "A year earlier, Nov 13, 2025",
      "value": "6.24%"
    },
    {
      "label": "Peak, Oct 26, 2023",
      "value": "7.79%"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "30-year mortgage rate, weekly: 7.11%",
        "subtitle": "+0.87 pts from a year earlier (6.24% on Nov 13, 2025). Peak, Oct 26, 2023: 7.79%."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "30-year fixed mortgage rate, weekly, %"
  }
};
</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 = [/* 306 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "point": "last",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    }
  },
  "metrics": [
    {
      "label": "Latest, Nov 12, 2026",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "A year earlier, Nov 13, 2025",
      "value": "6.24%"
    },
    {
      "label": "Peak, Oct 26, 2023",
      "value": "7.79%"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "30-year mortgage rate, weekly: 7.11%",
        "subtitle": "+0.87 pts from a year earlier (6.24% on Nov 13, 2025). Peak, Oct 26, 2023: 7.79%."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "30-year fixed mortgage rate, weekly, %"
  }
};
</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 = [/* 306 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2,
    "point": "last",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": false
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    }
  },
  "metrics": [
    {
      "label": "Latest, Nov 12, 2026",
      "value": "7.11%",
      "delta": "+0.87 pts",
      "deltaTone": "up"
    },
    {
      "label": "A year earlier, Nov 13, 2025",
      "value": "6.24%"
    },
    {
      "label": "Peak, Oct 26, 2023",
      "value": "7.79%"
    }
  ],
  "overrides": {
    "compact": {
      "chrome": {
        "title": "30-year mortgage rate, weekly: 7.11%",
        "subtitle": "+0.87 pts from a year earlier (6.24% on Nov 13, 2025). Peak, Oct 26, 2023: 7.79%."
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "30-year fixed mortgage rate, weekly, %"
  }
};

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

The first cell gives the latest rate with its change from a year earlier as a delta, colored by direction. The other cells give the rate a year earlier and the October 2023 peak, so the reader can see that 7.11% is high for the past five years without being the top.

Sparklines

A sparkline is a line chart stripped of its axes, gridlines, legend and source line, small enough to sit beside a number. In a box this small, axis labels would take more room than the line, and the reader wants direction, not exact values.

Mortgage rate, weekly: 7.11%Mortgage rate, weekly: 7.11%
A sparkline of the 30-year mortgage rate. Source: Freddie Mac, 30-Year Fixed Rate Mortgage Average (via FRED MORTGAGE30US).

Made with OpenChart. How to build this line chart

{
  "mark": {
    "type": "line",
    "interpolate": "linear",
    "stroke": "#0e7490"
  },
  "data": [
    {
      "date": "2021-01-07",
      "value": 2.65
    },
    {
      "date": "2021-01-14",
      "value": 2.79
    },
    {
      "date": "2021-01-21",
      "value": 2.77
    },
    {
      "date": "2021-01-28",
      "value": 2.73
    },
    {
      "date": "2021-02-04",
      "value": 2.73
    },
    {
      "date": "2021-02-11",
      "value": 2.73
    },
    // … 300 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "scale": {
        "domain": [
          2,
          10
        ]
      }
    }
  },
  "display": "sparkline",
  "chrome": {
    "title": "Mortgage rate, weekly: 7.11%"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear",
    "stroke": "#0e7490"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "scale": {
        "domain": [
          2,
          10
        ]
      }
    }
  },
  "display": "sparkline",
  "chrome": {
    "title": "Mortgage rate, weekly: 7.11%"
  }
};

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 = [/* 306 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear",
    "stroke": "#0e7490"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "scale": {
        "domain": [
          2,
          10
        ]
      }
    }
  },
  "display": "sparkline",
  "chrome": {
    "title": "Mortgage rate, weekly: 7.11%"
  }
};
</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 = [/* 306 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear",
    "stroke": "#0e7490"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "scale": {
        "domain": [
          2,
          10
        ]
      }
    }
  },
  "display": "sparkline",
  "chrome": {
    "title": "Mortgage rate, weekly: 7.11%"
  }
};
</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 = [/* 306 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear",
    "stroke": "#0e7490"
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "scale": {
        "domain": [
          2,
          10
        ]
      }
    }
  },
  "display": "sparkline",
  "chrome": {
    "title": "Mortgage rate, weekly: 7.11%"
  }
};

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

The line carries no scale, so it cannot say that the climb was from 2.65% to above 7%. The number has to sit beside it, here as its title.

Labeling a tile without axes

Dropping the axes and chrome removes the unit, the period and the source, so the tile has to supply them another way. The unit and the period go in the title, as in “weekly” and the % sign on the number. The source goes under the tile, as the line under each chart here does.

Name what was measured. The remote-work tile counts the share of Indeed job postings that mention remote or hybrid work, not the share of people who work remotely, and a title that said “remote work” would claim far more than the data shows.

Each tile scales its line to its own range, so two lines of the same height can stand for very different changes. Say so in the subtitle, as the dashboard does, or share a y domain when the sizes should compare.

Show gaps as gaps. The egg source has no price for October 2025, so the egg line breaks there instead of drawing a straight segment across the missing month. For the same reason the egg tile compares October 2026 with September 2025, the closest earlier month, and its label names that month.

Laying out the grid

The dashboard is one chart split into panels, one per KPI, each with its own y scale. A panel needs at least 200 pixels, so three fit side by side on a desktop and they stack into one column on a phone.

The metrics row shows only when the chart is at least 480 pixels wide and leaves at least 150 pixels for the plot. On a phone the metrics row drops out and the compact subtitle carries each latest reading and its change.

Keep the tiles in a row the same height, and put first the one the reader acts on first. Equal heights make the lines easier to compare for direction.

The spec

The dashboard is a line chart with encoding.facet on the tile name and columns: 3, and resolve: { scale: { y: "independent" } } gives each panel its own range. axis: false on x and y removes both axes, and scale: { zero: false } lets each line use the full panel height. A row with a null value breaks the line, which is how the missing egg month shows.

metrics is an array of cells shown above the plot, each a label and a value, with an optional delta and a deltaTone of "up" or "down" for its color. overrides.compact.chrome swaps in a phone title and subtitle. The code that builds the spec writes every label, value and delta from the same rows that draw the lines.

The sparkline sets display: "sparkline", which strips the axes, gridlines, legend and source. A chrome.title set explicitly stays, which is how the number sits above the line. A sparkline colors itself by trend unless mark.stroke is set, and a y scale.domain with room above the peak keeps the line clear of the title. In the single tile, mark.point: "last" puts a dot on the latest reading.

The dashboard tiles page shows the other tile forms, and the sparkline page covers display: "sparkline" in full.

The three width breakpoints, and what overrides can replace at each one, are on the responsive page.