Skip to content
OpenChart

Responsive

How a chart re-lays out from phone to desktop: the compact, medium and full breakpoints and the responsive settings.

A chart lays itself out again for the width it gets. These three figures are the same spec at full article width, at 560px and at 360px, the width of a phone.

20192020202120222023202402468Year-over-year change (%)Peak: 8.5%Pandemic low: 0.3%Fed target, 2%US inflation went from 0.3% in 2020 to a peakof 8.5% in 2022Consumer price index, year-over-year change, %, quarterly 2019–202420192020202120222023202402468Year-over-year change (%)Peak: 8.5%Pandemic low: 0.3%Fed target, 2%US inflation went from 0.3% in 2020 to a peakof 8.5% in 2022Consumer price index, year-over-year change, %, quarterly 2019–2024
US inflation at full width. Source: US Bureau of Labor Statistics, CPI-U (via FRED CPIAUCSL).
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    // … 18 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
20202022202402468Year-over-year change (%)Peak: 8.5%Pandemic low: 0.3%Fed target, 2%US inflation went from 0.3% in 2020to a peak of 8.5% in 2022Consumer price index, year-over-year change, %, quarterly 2019–202420202022202402468Year-over-year change (%)Peak: 8.5%Pandemic low: 0.3%Fed target, 2%US inflation went from 0.3% in 2020to a peak of 8.5% in 2022Consumer price index, year-over-year change, %, quarterly 2019–2024
US inflation at medium width. Source: US Bureau of Labor Statistics, CPI-U (via FRED CPIAUCSL).
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    // … 18 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
20202022202402468Year-over-year change (%)Peak: 8.5%2Fed target, 2%US inflation went from0.3% in 2020 to a peak of8.5% in 2022Consumer price index, year-over-year change, %,quarterly 2019–20242. Pandemic low: 0.3%20202022202402468Year-over-year change (%)Peak: 8.5%2Fed target, 2%US inflation went from0.3% in 2020 to a peak of8.5% in 2022Consumer price index, year-over-year change, %,quarterly 2019–20242. Pandemic low: 0.3%
US inflation at phone width. Source: US Bureau of Labor Statistics, CPI-U (via FRED CPIAUCSL).
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    // … 18 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  }
};

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

Breakpoints

The library sorts every chart into one of three breakpoints by the width of its container, and each breakpoint has its own layout rules:

Breakpoint Width What changes
Full over 700px Every value label, full axis ticks, callouts inline.
Medium 400 to 700px The most important labels, fewer ticks.
Compact under 400px No value labels, the fewest ticks, at most one inline callout.

At 360px the phone figure keeps one callout in place and turns the other into a numbered marker, with its text in a note under the plot. Height counts too: a chart 350px tall or less keeps its title and drops the subtitle, and one under 100px hides both.

overrides replaces parts of the spec at one breakpoint: the title and subtitle, labels, legend, annotations, or an axis or scale setting. overrides: { compact: { annotations: [] } } removes the callouts on phones only.

Keeping the last date

20162023010203040Share of generation (%)Coal16Gas44Nuclear19Hydro6Wind10Solar6Wind has generated more USelectricity than hydroevery year since 2019Share of generation from the six main sources, %,2016–202320162023010203040Share of generation (%)Coal16Gas44Nuclear19Hydro6Wind10Solar6Wind has generated more USelectricity than hydroevery year since 2019Share of generation from the six main sources, %,2016–2023
US electricity mix at phone width. Source: Our World in Data (owid/electricity-mix).
{
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "data": [
    {
      "year": "2016",
      "source": "Coal",
      "share": 31.2
    },
    {
      "year": "2016",
      "source": "Gas",
      "share": 34.8
    },
    {
      "year": "2016",
      "source": "Nuclear",
      "share": 20.3
    },
    {
      "year": "2016",
      "source": "Hydro",
      "share": 6.6
    },
    {
      "year": "2016",
      "source": "Wind",
      "share": 5.7
    },
    {
      "year": "2016",
      "source": "Solar",
      "share": 1.4
    },
    // … 42 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "format": ".0f",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".0f"
  },
  "chromeLayout": "subtract",
  "responsive": {
    "preserveEnd": true,
    "labelSummary": true
  },
  "chrome": {
    "title": "Wind has generated more US electricity than hydro every year since 2019",
    "subtitle": "Share of generation from the six main sources, %, 2016–2023"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "format": ".0f",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".0f"
  },
  "chromeLayout": "subtract",
  "responsive": {
    "preserveEnd": true,
    "labelSummary": true
  },
  "chrome": {
    "title": "Wind has generated more US electricity than hydro every year since 2019",
    "subtitle": "Share of generation from the six main sources, %, 2016–2023"
  }
};

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "format": ".0f",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".0f"
  },
  "chromeLayout": "subtract",
  "responsive": {
    "preserveEnd": true,
    "labelSummary": true
  },
  "chrome": {
    "title": "Wind has generated more US electricity than hydro every year since 2019",
    "subtitle": "Share of generation from the six main sources, %, 2016–2023"
  }
};
</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 = [/* 48 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "format": ".0f",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".0f"
  },
  "chromeLayout": "subtract",
  "responsive": {
    "preserveEnd": true,
    "labelSummary": true
  },
  "chrome": {
    "title": "Wind has generated more US electricity than hydro every year since 2019",
    "subtitle": "Share of generation from the six main sources, %, 2016–2023"
  }
};
</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 = [/* 48 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "format": ".0f",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".0f"
  },
  "chromeLayout": "subtract",
  "responsive": {
    "preserveEnd": true,
    "labelSummary": true
  },
  "chrome": {
    "title": "Wind has generated more US electricity than hydro every year since 2019",
    "subtitle": "Share of generation from the six main sources, %, 2016–2023"
  }
};

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

At compact width the x axis thins its ticks and can drop the last year, which on a time series is often the one the reader wants. responsive: { preserveEnd: true } keeps the final tick and thins the ones before it instead.

This chart also sets labelSummary: true, a fallback for the names at the right edge. Here all six still fit; when they cannot, the library moves the names and last values into a keyed list under the plot, so every series stays named.

More callouts on a phone

20202022202402468Year-over-year change (%)Peak: 8.5%Pandemic low: 0.3%Fed target, 2%US inflation went from0.3% in 2020 to a peak of8.5% in 2022Consumer price index, year-over-year change, %,quarterly 2019–202420202022202402468Year-over-year change (%)Peak: 8.5%Pandemic low: 0.3%Fed target, 2%US inflation went from0.3% in 2020 to a peak of8.5% in 2022Consumer price index, year-over-year change, %,quarterly 2019–2024
US inflation at phone width with both callouts. Source: US Bureau of Labor Statistics, CPI-U (via FRED CPIAUCSL).
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    // … 18 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  },
  "responsive": {
    "compactAnnotationLimit": 2
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  },
  "responsive": {
    "compactAnnotationLimit": 2
  }
};

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  },
  "responsive": {
    "compactAnnotationLimit": 2
  }
};
</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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  },
  "responsive": {
    "compactAnnotationLimit": 2
  }
};
</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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  },
  "responsive": {
    "compactAnnotationLimit": 2
  }
};

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

responsive: { compactAnnotationLimit: 2 } lets both callouts stay inline below 400px. The default is one. Set null for no limit, which suits callouts short enough to fit side by side. A callout that would overlap another still becomes a numbered note.

Fields that matter

Field What it does
responsive An object of the options below.
responsive.preserveEnd Keeps the final tick on a time axis when ticks are thinned.
responsive.labelSummary Moves end labels into a list under the plot when they cannot fit.
responsive.compactAnnotationLimit Inline callouts allowed below 400px. Default 1; null for no limit.
responsive.autoThin true by default: overlapping callouts become numbered notes. false hides them at compact width.
overrides Chrome, labels, legend, annotations and axis settings for one breakpoint: compact, medium or full.