Skip to content
OpenChart

Endpoint labels

Name each line at its end with its series and last value, so readers never match colors to a legend.

Endpoint labels name each line where it ends, so the reader does not have to match colors to a legend. content: "label" prints the series name alone.

201620182020202210%20%30%40%Share of generationCoalGasNuclearWindGas was the largest of the six main sources ofUS electricity in every year from 2016 to 2023Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.201620182020202210%20%30%40%Share of generationCoalGasNuclearWindGas was the largest of the six main sources ofUS electricity in every year from 2016 to 2023Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.
Four US electricity sources labeled by name. 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": "Wind",
      "share": 5.7
    },
    {
      "year": "2017",
      "source": "Coal",
      "share": 30.7
    },
    {
      "year": "2017",
      "source": "Gas",
      "share": 33
    },
    // … 26 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "label"
  },
  "chrome": {
    "title": "Gas was the largest of the six main sources of US electricity in every year from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "label"
  },
  "chrome": {
    "title": "Gas was the largest of the six main sources of US electricity in every year from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "label"
  },
  "chrome": {
    "title": "Gas was the largest of the six main sources of US electricity in every year from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "label"
  },
  "chrome": {
    "title": "Gas was the largest of the six main sources of US electricity in every year from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "label"
  },
  "chrome": {
    "title": "Gas was the largest of the six main sources of US electricity in every year from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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

Names only

A line chart with two to eight series gets endpoint labels without any setting, and they replace the legend. Set endpointLabels to choose what each entry says. Names alone suit a chart whose title is about rank or order, where the exact last values would add nothing.

Values only

201620182020202210%20%30%40%Share of generation16.243.518.610.1CoalGasNuclearWindWind's share of generation from the six mainsources was 10.1% in 2023, up from 5.7% in2016Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.201620182020202210%20%30%40%Share of generation16.243.518.610.1CoalGasNuclearWindWind's share of generation from the six mainsources was 10.1% in 2023, up from 5.7% in2016Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.
Four US electricity sources labeled by 2023 share. 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": "Wind",
      "share": 5.7
    },
    {
      "year": "2017",
      "source": "Coal",
      "share": 30.7
    },
    {
      "year": "2017",
      "source": "Gas",
      "share": 33
    },
    // … 26 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "value",
    "format": ".1f"
  },
  "legend": {
    "show": true,
    "position": "top"
  },
  "chrome": {
    "title": "Wind's share of generation from the six main sources was 10.1% in 2023, up from 5.7% in 2016",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "value",
    "format": ".1f"
  },
  "legend": {
    "show": true,
    "position": "top"
  },
  "chrome": {
    "title": "Wind's share of generation from the six main sources was 10.1% in 2023, up from 5.7% in 2016",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "value",
    "format": ".1f"
  },
  "legend": {
    "show": true,
    "position": "top"
  },
  "chrome": {
    "title": "Wind's share of generation from the six main sources was 10.1% in 2023, up from 5.7% in 2016",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "value",
    "format": ".1f"
  },
  "legend": {
    "show": true,
    "position": "top"
  },
  "chrome": {
    "title": "Wind's share of generation from the six main sources was 10.1% in 2023, up from 5.7% in 2016",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "content": "value",
    "format": ".1f"
  },
  "legend": {
    "show": true,
    "position": "top"
  },
  "chrome": {
    "title": "Wind's share of generation from the six main sources was 10.1% in 2023, up from 5.7% in 2016",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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

content: "value" prints each line’s last value, formatted by format: ".1f". Values alone do not say which line is which, so this chart turns the legend back on with legend: { show: true, position: "top" }. Use it when the title turns on the final numbers.

Name and value

201620182020202210%20%30%40%Share of generationCoal16.2Gas43.5Nuclear18.6Wind10.1Coal fell to 16.2% of generation from the sixmain sources in 2023, behind gas and nuclearShare of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.201620182020202210%20%30%40%Share of generationCoal16.2Gas43.5Nuclear18.6Wind10.1Coal fell to 16.2% of generation from the sixmain sources in 2023, behind gas and nuclearShare of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.
Four US electricity sources labeled by name and 2023 share. 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": "Wind",
      "share": 5.7
    },
    {
      "year": "2017",
      "source": "Coal",
      "share": 30.7
    },
    {
      "year": "2017",
      "source": "Gas",
      "share": 33
    },
    // … 26 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".1f"
  },
  "chrome": {
    "title": "Coal fell to 16.2% of generation from the six main sources in 2023, behind gas and nuclear",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".1f"
  },
  "chrome": {
    "title": "Coal fell to 16.2% of generation from the six main sources in 2023, behind gas and nuclear",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".1f"
  },
  "chrome": {
    "title": "Coal fell to 16.2% of generation from the six main sources in 2023, behind gas and nuclear",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".1f"
  },
  "chrome": {
    "title": "Coal fell to 16.2% of generation from the six main sources in 2023, behind gas and nuclear",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".1f"
  },
  "chrome": {
    "title": "Coal fell to 16.2% of generation from the six main sources in 2023, behind gas and nuclear",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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

Leaving content out prints the name with the value on a second line. "label value" puts both on one line, which takes less height. When two lines end close together, the engine moves their entries apart; showLeader: true draws a line back from a moved entry to its endpoint.

One series in focus

201620182020202210%20%30%40%Share of generationCoal 16.2Gas 43.5Nuclear 18.6Wind 10.1Gas's share of generation from the six mainsources rose by 8.7 points from 2016 to 2023Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.201620182020202210%20%30%40%Share of generationCoal 16.2Gas 43.5Nuclear 18.6Wind 10.1Gas's share of generation from the six mainsources rose by 8.7 points from 2016 to 2023Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solarare not drawn.
US electricity sources with gas in focus. 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": "Wind",
      "share": 5.7
    },
    {
      "year": "2017",
      "source": "Coal",
      "share": 30.7
    },
    {
      "year": "2017",
      "source": "Gas",
      "share": 33
    },
    // … 26 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal",
      "scale": {
        "domain": [
          "Gas",
          "Nuclear",
          "Coal",
          "Wind"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "endpointLabels": {
    "content": "label value",
    "format": ".1f"
  },
  "seriesStyles": {
    "Gas": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Gas's share of generation from the six main sources rose by 8.7 points from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal",
      "scale": {
        "domain": [
          "Gas",
          "Nuclear",
          "Coal",
          "Wind"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "endpointLabels": {
    "content": "label value",
    "format": ".1f"
  },
  "seriesStyles": {
    "Gas": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Gas's share of generation from the six main sources rose by 8.7 points from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal",
      "scale": {
        "domain": [
          "Gas",
          "Nuclear",
          "Coal",
          "Wind"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "endpointLabels": {
    "content": "label value",
    "format": ".1f"
  },
  "seriesStyles": {
    "Gas": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Gas's share of generation from the six main sources rose by 8.7 points from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal",
      "scale": {
        "domain": [
          "Gas",
          "Nuclear",
          "Coal",
          "Wind"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "endpointLabels": {
    "content": "label value",
    "format": ".1f"
  },
  "seriesStyles": {
    "Gas": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Gas's share of generation from the six main sources rose by 8.7 points from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};
</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 = [/* 32 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",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal",
      "scale": {
        "domain": [
          "Gas",
          "Nuclear",
          "Coal",
          "Wind"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "endpointLabels": {
    "content": "label value",
    "format": ".1f"
  },
  "seriesStyles": {
    "Gas": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Gas's share of generation from the six main sources rose by 8.7 points from 2016 to 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Hydro and solar are not drawn."
  }
};

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

An explicit color scale maps gas to the accent color and the other three sources to grey, and seriesStyles thickens the gas line. The endpoint labels still name every line, so the grey ones stay readable as context. content: "label value" keeps each entry on one line.

Fields that matter

Field What it does
endpointLabels true, false or a config object. Omitted, it turns on for two to eight line series.
endpointLabels.content "label", "value" or "label value". Omitted, the name sits over the value.
endpointLabels.format d3-format string for the value. Defaults to the y axis format.
endpointLabels.ends "end", or "both" to label the left end too.
endpointLabels.showMarker The ring on each line’s last point. Default true.
endpointLabels.showLeader A line from a displaced entry back to its endpoint.
endpointLabels.maxSeries Above this many series, endpoint labels give way to a legend. Default 8.