Skip to content

Plot

Creates an x/y plot based on an array of data.

The simplest scatter plot: each row becomes a point positioned by its x and y values, with groupBy giving every id its own color.

const config = {
  data: [
    {id: "alpha", x: 4, y: 7},
    {id: "beta", x: 5, y: 2},
    {id: "gamma", x: 6, y: 13},
    {id: "delta", x: 2, y: 11},
    {id: "epsilon", x: 5, y: 5},
    {id: "zeta", x: 3, y: 4},
    {id: "eta", x: 2.5, y: 6},
    {id: "theta", x: 5.5, y: 9},
  ],
  groupBy: "id",
  x: "x",
  y: "y",
};

Map a third variable to point radius with size, turning the scatter into a bubble chart; sizeMin and sizeMax clamp the radius range so extreme values stay legible. BubbleChart sets this up for you, sizing bubbles by area.

const config = {
  data: [
    {id: "alpha", x: 4, y: 7, value: 240},
    {id: "beta", x: 5, y: 2, value: 120},
    {id: "gamma", x: 6, y: 13, value: 180},
  ],
  groupBy: "id",
  size: "value",
  sizeMax: 90,
  sizeMin: 20,
  x: "x",
  y: "y",
};

Hover a bubble: a dashed guide runs from its center to each axis, and a badge in the bubble’s color shows its value where the guide meets the axis, formatted as the tooltip formats that axis. On by default on every Plot chart — on a chart with a discrete axis the shared tooltip’s crosshair is that axis’s guide, and a bar is badged on its value axis only. Set axisHover: false to turn it off (or "x"/"y" for one direction), and style the guides and badges with axisHoverConfig.guideConfig and axisHoverConfig.badgeConfig.

const config = {
  data: [
    {id: "alpha", gdp: 1200, life: 64.2, population: 12},
    {id: "beta", gdp: 2400, life: 70.8, population: 40},
    {id: "gamma", gdp: 3100, life: 68.1, population: 22},
    {id: "delta", gdp: 4600, life: 75.4, population: 31},
    {id: "epsilon", gdp: 5200, life: 72.9, population: 8},
  ],
  groupBy: "id",
  size: "population",
  x: "gdp",
  y: "life",
  axisHover: true,
  axisHoverConfig: {
    guideConfig: {strokeDasharray: "4 3", strokeWidth: 1},
    badgeConfig: {fontSize: 12, padding: 4},
  },
};

Small points are hard to land on, so a scatter or bubble Plot acts on the closest point within hoverDistance pixels of the pointer (20 by default): its tooltip (pointing at the point itself, not the cursor), hover highlight and axis guides show, and a click there clicks it. Network nodes and Geomap points work the same way, while bars, areas and other area-filling marks keep exact hit-testing. Set hoverDistance: 0 to only react to the point under the pointer, with a cursor-following tooltip.

const config = {
  data: Array.from({length: 120}, (_, i) => ({
    id: `Point ${i + 1}`,
    x: Math.round((50 + 30 * Math.sin(i * 1.7) * Math.cos(i * 0.31)) * 10) / 10,
    y: Math.round((50 + 30 * Math.cos(i * 2.3) * Math.sin(i * 0.17)) * 10) / 10,
  })),
  groupBy: "id",
  x: "x",
  y: "y",
  legend: false,
  hoverDistance: 20,
  shapeConfig: {Circle: {r: 3}},
};

Press play on the timeline: each point trails a tapering cone from its previous year’s position to its current one, colored with a gradient that fades to transparent at the tail (which narrows to the point’s pre-move size) and fading out as it arrives. On by default for scatter points — opt out with shapeConfig.Circle.trail: false. Works on both the SVG and Canvas backends — toggle renderer to compare.

const config = {
  data: [
    {id: "alpha", year: 2019, x: 2, y: 3, value: 180},
    {id: "alpha", year: 2020, x: 5, y: 8, value: 180},
    {id: "alpha", year: 2021, x: 9, y: 5, value: 180},
    {id: "alpha", year: 2022, x: 12, y: 11, value: 180},
    {id: "beta", year: 2019, x: 11, y: 12, value: 120},
    {id: "beta", year: 2020, x: 8, y: 6, value: 120},
    {id: "beta", year: 2021, x: 4, y: 9, value: 120},
    {id: "beta", year: 2022, x: 2, y: 2, value: 120},
    {id: "gamma", year: 2019, x: 6, y: 1, value: 240},
    {id: "gamma", year: 2020, x: 3, y: 10, value: 240},
    {id: "gamma", year: 2021, x: 10, y: 8, value: 240},
    {id: "gamma", year: 2022, x: 7, y: 4, value: 240},
  ],
  // duration: 2000,
  groupBy: "id",
  time: "year",
  shapeConfig: {
    trail: true,
  },
  size: "value",
  sizeMax: 40,
  sizeMin: 24,
  x: "x",
  y: "y",
};

Trails aren’t circle-only: Rect marks trail too, and the cone is sized to the square’s silhouette perpendicular to travel — so a square moving diagonally reaches corner-to-corner rather than edge-to-edge, matching what the eye sees. Also on by default for scatter squares; opt out with shapeConfig.Rect.trail: false.

renderer

Selects which @d3plus/render backend paints the visible output. "svg" = SvgRenderer (default), "canvas" = CanvasRenderer. Boolean arguments both normalize to "svg".

A Hans Rosling-style health-and-wealth view: press play and each nation’s bubble ebbs and flows but trends from the poor, short-lived bottom-left toward the rich, long-lived top-right, leaving a persistent trail of its path. By default a trail shows only the current move and fades on arrival; shapeConfig.Circle.trailPersist keeps past moves too — a number keeps that many step-segments, true a long slowly-fading tail. Trails follow the timeline’s direction: they grow forward and rewind (the newest segment retracting) when you step back. The whole trail draws as one shape, so overlapping turns don’t darken. Setting trailPersist is all you need — it switches the chart to fixed axes and a single-period timeline internally (the conditions a persistent trail needs).

renderer

Selects which @d3plus/render backend paints the visible output. "svg" = SvgRenderer (default), "canvas" = CanvasRenderer. Boolean arguments both normalize to "svg".

Render each circle as an image by setting shapeConfig.Circle.backgroundImage to a per-datum URL (and blanking the label) — here country icons stand in for the bubbles on a GDP-versus-complexity plot.

const config = {
  // Approximate 2019 economic complexity (ECI), GDP (Measure), and trade, in US dollars.
  data: [
    {
      Country: "Japan",
      "Country ID": "asjpn",
      ECI: 2.26,
      Measure: 5.08e12,
      "Trade Value": 7e11,
    },
    {
      Country: "Switzerland",
      "Country ID": "euche",
      ECI: 2.0,
      Measure: 7e11,
      "Trade Value": 3.1e11,
    },
    {
      Country: "Germany",
      "Country ID": "eudeu",
      ECI: 1.92,
      Measure: 3.86e12,
      "Trade Value": 1.45e12,
    },
    {
      Country: "South Korea",
      "Country ID": "askor",
      ECI: 1.9,
      Measure: 1.65e12,
      "Trade Value": 5.4e11,
    },
    {
      Country: "United Kingdom",
      "Country ID": "eugbr",
      ECI: 1.5,
      Measure: 2.83e12,
      "Trade Value": 4.6e11,
    },
    {
      Country: "United States",
      "Country ID": "nausa",
      ECI: 1.4,
      Measure: 2.14e13,
      "Trade Value": 1.5e12,
    },
    {
      Country: "France",
      "Country ID": "eufra",
      ECI: 1.2,
      Measure: 2.72e12,
      "Trade Value": 5.5e11,
    },
    {
      Country: "Mexico",
      "Country ID": "namex",
      ECI: 1.1,
      Measure: 1.27e12,
      "Trade Value": 4.5e11,
    },
    {
      Country: "China",
      "Country ID": "aschn",
      ECI: 1.0,
      Measure: 1.43e13,
      "Trade Value": 2.5e12,
    },
    {
      Country: "India",
      "Country ID": "asind",
      ECI: 0.5,
      Measure: 2.87e12,
      "Trade Value": 3.2e11,
    },
    {
      Country: "Turkey",
      "Country ID": "astur",
      ECI: 0.4,
      Measure: 7.6e11,
      "Trade Value": 1.8e11,
    },
    {
      Country: "Brazil",
      "Country ID": "sabra",
      ECI: 0.2,
      Measure: 1.84e12,
      "Trade Value": 2.2e11,
    },
    {
      Country: "South Africa",
      "Country ID": "afzaf",
      ECI: 0.1,
      Measure: 3.5e11,
      "Trade Value": 9e10,
    },
    {
      Country: "Indonesia",
      "Country ID": "asidn",
      ECI: -0.1,
      Measure: 1.12e12,
      "Trade Value": 1.6e11,
    },
    {
      Country: "Saudi Arabia",
      "Country ID": "assau",
      ECI: -0.2,
      Measure: 7.9e11,
      "Trade Value": 2.5e11,
    },
    {
      Country: "Chile",
      "Country ID": "sachl",
      ECI: -0.3,
      Measure: 2.8e11,
      "Trade Value": 6.8e10,
    },
    {
      Country: "Australia",
      "Country ID": "ocaus",
      ECI: -0.5,
      Measure: 1.39e12,
      "Trade Value": 2.6e11,
    },
    {
      Country: "Nigeria",
      "Country ID": "afnga",
      ECI: -1.3,
      Measure: 4.5e11,
      "Trade Value": 5.6e10,
    },
  ],
  groupBy: "Country",
  shapeConfig: {
    Circle: {
      backgroundImage: d =>
        `https://oec.world/images/icons/country/country_${d["Country ID"].slice(2, 5)}_circle.png`,
      label: () => "",
    },
  },
  size: "Trade Value",
  sizeMax: 50,
  x: "ECI",
  y: "Measure",
};

Layer custom shapes over the data with annotations. Each entry names a shape, brings its own data in the same x/y units as the marks, and sits "back" (default) or "front" of them via layer. Here a dashed Line with a Rect text label marks a revenue target, and a pull-out label calls out one store: a Circle ring around the point, a Line leader, and a Rect callout carrying a label. Width, height and radius are in pixels. To draw a fitted trend line, use trendLine instead.

const config = {
  data: [
    {store: "Store 1", visitors: 4.2, revenue: 48},
    {store: "Store 2", visitors: 5.1, revenue: 61},
    {store: "Store 3", visitors: 6.0, revenue: 66},
    {store: "Store 4", visitors: 6.8, revenue: 79},
    {store: "Store 5", visitors: 7.5, revenue: 84},
    {store: "Store 6", visitors: 8.3, revenue: 97},
    {store: "Store 7", visitors: 9.0, revenue: 182},
    {store: "Store 8", visitors: 9.6, revenue: 108},
    {store: "Store 9", visitors: 10.4, revenue: 121},
    {store: "Store 10", visitors: 11.2, revenue: 126},
    {store: "Store 11", visitors: 12.1, revenue: 139},
    {store: "Store 12", visitors: 13.0, revenue: 150},
  ],
  groupBy: "store",
  x: "visitors",
  y: "revenue",
  legend: false,
  shapeConfig: {Circle: {fill: "#4dabf7"}},
  annotations: [
    // A dashed reference line across the plot, with a small text label above it.
    {
      shape: "Line",
      data: [
        {id: "target", x: 4, y: 100},
        {id: "target", x: 13.4, y: 100},
      ],
      stroke: "#adb5bd",
      strokeDasharray: "6 4",
      strokeWidth: 1.5,
    },
    {
      shape: "Rect",
      data: [{id: "target-label", x: 4.9, y: 106, width: 84, height: 18}],
      fill: "transparent",
      label: "Target: $100k",
      labelConfig: {
        fontColor: "#868e96",
        fontSize: 11,
        padding: 0,
        textAnchor: "start",
        verticalAlign: "middle",
      },
    },
    // A pull-out label for one data point: a ring around it, a leader line, and a callout box,
    // all drawn in front of the marks.
    {
      shape: "Circle",
      layer: "front",
      data: [{id: "ring", x: 9.0, y: 182, r: 13}],
      fill: "transparent",
      stroke: "#c92a2a",
      strokeWidth: 2,
    },
    {
      shape: "Line",
      layer: "front",
      data: [
        {id: "leader", x: 9.35, y: 180},
        {id: "leader", x: 10.6, y: 172},
      ],
      stroke: "#c92a2a",
      strokeWidth: 1.5,
    },
    {
      shape: "Rect",
      layer: "front",
      data: [{id: "callout", x: 11.8, y: 172, width: 150, height: 40}],
      fill: "#fff5f5",
      stroke: "#c92a2a",
      strokeWidth: 1.5,
      label: "Store 7\n$182k from 9k visitors",
      labelConfig: {
        fontColor: "#c92a2a",
        fontSize: 12,
        padding: 4,
        textAnchor: "middle",
        verticalAlign: "middle",
      },
    },
  ],
};

The same notes as above, without hand-built shapes. referenceLines draws a line across the plot at a value (dash: true dashes it) with a label at its end, and referenceBands shades the span between two values, labeled in its corner; both sit behind the data (their labels above it), and widen the axis to stay in view. A "Callout" annotation anchors wrapped text in a box at each row’s x/y, offset by dx/dy pixels, with a connector ending in an arrowhead (or marker: "dot"), and stays inside the plot. xRef/yRef: "plot" position a callout by fractions of the plot area instead. Colors follow the chart’s theme; every style can be overridden.

const config = {
  data: [
    {store: "Store 1", visitors: 4.2, revenue: 48},
    {store: "Store 2", visitors: 5.1, revenue: 61},
    {store: "Store 3", visitors: 6.0, revenue: 66},
    {store: "Store 4", visitors: 6.8, revenue: 79},
    {store: "Store 5", visitors: 7.5, revenue: 84},
    {store: "Store 6", visitors: 8.3, revenue: 97},
    {store: "Store 7", visitors: 9.0, revenue: 182},
    {store: "Store 8", visitors: 9.6, revenue: 108},
    {store: "Store 9", visitors: 10.4, revenue: 121},
    {store: "Store 10", visitors: 11.2, revenue: 126},
    {store: "Store 11", visitors: 12.1, revenue: 139},
    {store: "Store 12", visitors: 13.0, revenue: 150},
  ],
  groupBy: "store",
  x: "visitors",
  y: "revenue",
  legend: false,
  referenceLines: [{y: 100, label: "Target: $100k", dash: true}],
  referenceBands: [{x: [8, 10], label: "Weekend promotion"}],
  annotations: [
    {
      shape: "Callout",
      data: [
        {
          x: 9.0,
          y: 182,
          label: "Store 7: $182k from 9k visitors",
        },
      ],
      dx: 90,
      dy: 10,
      maxWidth: 110,
      marker: "dot",
    },
    {
      shape: "Callout",
      xRef: "plot",
      yRef: "plot",
      data: [{x: 0.02, y: 0.98, label: "Revenue by store"}],
      dx: 60,
      dy: 12,
      connector: false,
      fill: "none",
      stroke: "none",
      textAlign: "start",
      fontWeight: 600,
    },
  ],
};

Set trendLine: true to fit a least-squares line to the plotted data. Each series (here the parent region of each point) gets its own dashed line in its color, drawn behind the marks. Hover a line for its equation, R² and number of observations.

const config = {
  data: [
    {region: "North", id: "North 1", x: 1.0, y: 8.8},
    {region: "North", id: "North 2", x: 1.8, y: 8.8},
    {region: "North", id: "North 3", x: 2.6, y: 14.0},
    {region: "North", id: "North 4", x: 3.4, y: 12.7},
    {region: "North", id: "North 5", x: 4.2, y: 13.2},
    {region: "North", id: "North 6", x: 5.0, y: 18.8},
    {region: "North", id: "North 7", x: 5.8, y: 26.6},
    {region: "North", id: "North 8", x: 6.6, y: 26.8},
    {region: "North", id: "North 9", x: 7.4, y: 28.0},
    {region: "North", id: "North 10", x: 8.2, y: 23.1},
    {region: "North", id: "North 11", x: 9.0, y: 28.4},
    {region: "North", id: "North 12", x: 9.8, y: 26.9},
    {region: "South", id: "South 1", x: 1.0, y: 17.1},
    {region: "South", id: "South 2", x: 1.8, y: 18.7},
    {region: "South", id: "South 3", x: 2.6, y: 22.4},
    {region: "South", id: "South 4", x: 3.4, y: 33.3},
    {region: "South", id: "South 5", x: 4.2, y: 34.5},
    {region: "South", id: "South 6", x: 5.0, y: 36.7},
    {region: "South", id: "South 7", x: 5.8, y: 39.0},
    {region: "South", id: "South 8", x: 6.6, y: 34.1},
    {region: "South", id: "South 9", x: 7.4, y: 37.9},
    {region: "South", id: "South 10", x: 8.2, y: 44.1},
    {region: "South", id: "South 11", x: 9.0, y: 47.8},
    {region: "South", id: "South 12", x: 9.8, y: 51.7},
    {region: "West", id: "West 1", x: 1.0, y: 34.6},
    {region: "West", id: "West 2", x: 1.8, y: 28.2},
    {region: "West", id: "West 3", x: 2.6, y: 37.7},
    {region: "West", id: "West 4", x: 3.4, y: 41.7},
    {region: "West", id: "West 5", x: 4.2, y: 42.9},
    {region: "West", id: "West 6", x: 5.0, y: 42.1},
    {region: "West", id: "West 7", x: 5.8, y: 48.9},
    {region: "West", id: "West 8", x: 6.6, y: 47.5},
    {region: "West", id: "West 9", x: 7.4, y: 60.8},
    {region: "West", id: "West 10", x: 8.2, y: 63.2},
    {region: "West", id: "West 11", x: 9.0, y: 62.6},
    {region: "West", id: "West 12", x: 9.8, y: 62.8},
  ],
  groupBy: ["region", "id"],
  x: "x",
  y: "y",
  trendLine: true,
};

trendLineConfig.group: "all" fits one line to every point instead of one per series, and confidence: true shades the 95% confidence band for the line (set confidenceLevel to change it, and confidenceConfig to style it). Bands are drawn for linear fits only.

const config = {
  data: [
    {region: "North", id: "North 1", x: 1.0, y: 8.8},
    {region: "North", id: "North 2", x: 1.8, y: 8.8},
    {region: "North", id: "North 3", x: 2.6, y: 14.0},
    {region: "North", id: "North 4", x: 3.4, y: 12.7},
    {region: "North", id: "North 5", x: 4.2, y: 13.2},
    {region: "North", id: "North 6", x: 5.0, y: 18.8},
    {region: "North", id: "North 7", x: 5.8, y: 26.6},
    {region: "North", id: "North 8", x: 6.6, y: 26.8},
    {region: "North", id: "North 9", x: 7.4, y: 28.0},
    {region: "North", id: "North 10", x: 8.2, y: 23.1},
    {region: "North", id: "North 11", x: 9.0, y: 28.4},
    {region: "North", id: "North 12", x: 9.8, y: 26.9},
    {region: "South", id: "South 1", x: 1.0, y: 17.1},
    {region: "South", id: "South 2", x: 1.8, y: 18.7},
    {region: "South", id: "South 3", x: 2.6, y: 22.4},
    {region: "South", id: "South 4", x: 3.4, y: 33.3},
    {region: "South", id: "South 5", x: 4.2, y: 34.5},
    {region: "South", id: "South 6", x: 5.0, y: 36.7},
    {region: "South", id: "South 7", x: 5.8, y: 39.0},
    {region: "South", id: "South 8", x: 6.6, y: 34.1},
    {region: "South", id: "South 9", x: 7.4, y: 37.9},
    {region: "South", id: "South 10", x: 8.2, y: 44.1},
    {region: "South", id: "South 11", x: 9.0, y: 47.8},
    {region: "South", id: "South 12", x: 9.8, y: 51.7},
    {region: "West", id: "West 1", x: 1.0, y: 34.6},
    {region: "West", id: "West 2", x: 1.8, y: 28.2},
    {region: "West", id: "West 3", x: 2.6, y: 37.7},
    {region: "West", id: "West 4", x: 3.4, y: 41.7},
    {region: "West", id: "West 5", x: 4.2, y: 42.9},
    {region: "West", id: "West 6", x: 5.0, y: 42.1},
    {region: "West", id: "West 7", x: 5.8, y: 48.9},
    {region: "West", id: "West 8", x: 6.6, y: 47.5},
    {region: "West", id: "West 9", x: 7.4, y: 60.8},
    {region: "West", id: "West 10", x: 8.2, y: 63.2},
    {region: "West", id: "West 11", x: 9.0, y: 62.6},
    {region: "West", id: "West 12", x: 9.8, y: 62.8},
  ],
  groupBy: ["region", "id"],
  x: "x",
  y: "y",
  trendLine: "linear",
  trendLineConfig: {
    group: "all",
    confidence: true,
  },
};

Besides "linear", trendLine accepts "exponential", "logarithmic", "power" and "polynomial" (with trendLineConfig.order setting the degree). Other trendLineConfig keys style the line: here a solid red cubic fit. Points with a single groupBy level are each their own series, so they share one trend line.

const config = {
  data: [
    {id: "p1", x: 0.0, y: -36.7},
    {id: "p2", x: 0.5, y: -26.9},
    {id: "p3", x: 1.0, y: -14.5},
    {id: "p4", x: 1.5, y: -7.4},
    {id: "p5", x: 2.0, y: -4.7},
    {id: "p6", x: 2.5, y: -1.9},
    {id: "p7", x: 3.0, y: 1.6},
    {id: "p8", x: 3.5, y: 1.1},
    {id: "p9", x: 4.0, y: -1.1},
    {id: "p10", x: 4.5, y: -0.6},
    {id: "p11", x: 5.0, y: 2.5},
    {id: "p12", x: 5.5, y: -4.6},
    {id: "p13", x: 6.0, y: -5.2},
    {id: "p14", x: 6.5, y: -0.6},
    {id: "p15", x: 7.0, y: -2.6},
    {id: "p16", x: 7.5, y: 1.5},
    {id: "p17", x: 8.0, y: 4.6},
    {id: "p18", x: 8.5, y: 8.9},
    {id: "p19", x: 9.0, y: 21.6},
    {id: "p20", x: 9.5, y: 25.0},
  ],
  groupBy: "id",
  x: "x",
  y: "y",
  legend: false,
  trendLine: "polynomial",
  trendLineConfig: {
    order: 3,
    stroke: "#c92a2a",
    strokeDasharray: "none",
  },
};

On a continuous axis, trendLineConfig.projection with {to} extends the fit to that value; the x axis widens to fit it. A number would step that many times past the last value, by the median gap between values. With confidence, the band beyond the data is a prediction interval, wider than the confidence band, since it covers where individual new points could fall.

const config = {
  data: [
    {region: "North", id: "North 1", x: 1.0, y: 8.8},
    {region: "North", id: "North 2", x: 1.8, y: 8.8},
    {region: "North", id: "North 3", x: 2.6, y: 14.0},
    {region: "North", id: "North 4", x: 3.4, y: 12.7},
    {region: "North", id: "North 5", x: 4.2, y: 13.2},
    {region: "North", id: "North 6", x: 5.0, y: 18.8},
    {region: "North", id: "North 7", x: 5.8, y: 26.6},
    {region: "North", id: "North 8", x: 6.6, y: 26.8},
    {region: "North", id: "North 9", x: 7.4, y: 28.0},
    {region: "North", id: "North 10", x: 8.2, y: 23.1},
    {region: "North", id: "North 11", x: 9.0, y: 28.4},
    {region: "North", id: "North 12", x: 9.8, y: 26.9},
    {region: "South", id: "South 1", x: 1.0, y: 17.1},
    {region: "South", id: "South 2", x: 1.8, y: 18.7},
    {region: "South", id: "South 3", x: 2.6, y: 22.4},
    {region: "South", id: "South 4", x: 3.4, y: 33.3},
    {region: "South", id: "South 5", x: 4.2, y: 34.5},
    {region: "South", id: "South 6", x: 5.0, y: 36.7},
    {region: "South", id: "South 7", x: 5.8, y: 39.0},
    {region: "South", id: "South 8", x: 6.6, y: 34.1},
    {region: "South", id: "South 9", x: 7.4, y: 37.9},
    {region: "South", id: "South 10", x: 8.2, y: 44.1},
    {region: "South", id: "South 11", x: 9.0, y: 47.8},
    {region: "South", id: "South 12", x: 9.8, y: 51.7},
    {region: "West", id: "West 1", x: 1.0, y: 34.6},
    {region: "West", id: "West 2", x: 1.8, y: 28.2},
    {region: "West", id: "West 3", x: 2.6, y: 37.7},
    {region: "West", id: "West 4", x: 3.4, y: 41.7},
    {region: "West", id: "West 5", x: 4.2, y: 42.9},
    {region: "West", id: "West 6", x: 5.0, y: 42.1},
    {region: "West", id: "West 7", x: 5.8, y: 48.9},
    {region: "West", id: "West 8", x: 6.6, y: 47.5},
    {region: "West", id: "West 9", x: 7.4, y: 60.8},
    {region: "West", id: "West 10", x: 8.2, y: 63.2},
    {region: "West", id: "West 11", x: 9.0, y: 62.6},
    {region: "West", id: "West 12", x: 9.8, y: 62.8},
  ],
  groupBy: ["region", "id"],
  x: "x",
  y: "y",
  trendLine: "linear",
  trendLineConfig: {
    group: "all",
    confidence: true,
    projection: {to: 14},
  },
};

Pass a function to shape to choose a mark type per datum — some points draw as Rect, the rest as Circle — letting one plot encode a category through shape.

const config = {
  data: [
    {value: 100, weight: 0.45, name: "alpha"},
    {value: 70, weight: 0.6, name: "beta"},
    {value: 40, weight: -0.2, name: "gamma"},
    {value: 15, weight: 0.1, name: "delta"},
    {value: 5, weight: -0.43, name: "epsilon"},
    {value: 1, weight: 0, name: "zeta"},
  ],
  groupBy: "name",
  shape: d =>
    d.name === "alpha" || d.name === "delta" || d.name === "epsilon"
      ? "Rect"
      : "Circle",
  size: "value",
  x: "value",
  y: "weight",
};

When a plot mixes shape types, shapeSort sets the order they are drawn — the comparator here renders Line marks before Circles so the points sit on top of the connecting line.

const config = {
  data: [
    {id: "alpha", time: 4, value: 240},
    {id: "beta", time: 5, value: 120},
    {id: "gamma", time: 6, value: 180},
    {id: "delta", time: 4, value: 240},
    {id: "delta", time: 5, value: 120},
    {id: "delta", time: 6, value: 180},
  ],
  groupBy: "id",
  shape: d => (d.id === "delta" ? "Line" : "Circle"),
  shapeConfig: {
    Line: {
      strokeLinecap: "round",
      strokeWidth: 5,
    },
  },
  shapeSort: (a, b) =>
    ["Circle", "Line"].indexOf(b) - ["Circle", "Line"].indexOf(a),
  sizeMin: 20,
  x: "time",
  y: "value",
};

When size sizes the bubbles by more than one value, a size legend appears in the chart’s bottom-right corner. Its circles are drawn at the same radii as the chart’s bubbles, so the largest circle matches the largest bubble exactly. When size is a data key, that key becomes the legend’s title. By default the legend takes room from the right margin, so the chart keeps its full height. Set sizeLegendPosition to "bottom" to take room from the bottom instead, or sizeLegend to false to hide it.

const config = {
  data: [
    {id: "Alpha", x: 4, y: 7, revenue: 120},
    {id: "Beta", x: 5, y: 2, revenue: 1450},
    {id: "Gamma", x: 6, y: 9, revenue: 640},
    {id: "Delta", x: 2, y: 4, revenue: 80},
    {id: "Epsilon", x: 8, y: 5, revenue: 2300},
    {id: "Zeta", x: 3, y: 8, revenue: 900},
    {id: "Eta", x: 7, y: 3, revenue: 310},
    {id: "Theta", x: 9, y: 8, revenue: 1800},
  ],
  groupBy: "id",
  legendPosition: "bottom",
  size: "revenue",
  sizeMax: 36,
  sizeMin: 4,
  x: "x",
  y: "y",
};

sizeLegendConfig customizes the size legend: title, values (the circles to draw), tickFormat, and styling through shapeConfig, lineConfig, labelConfig, and titleConfig. A colorScale on the right shares the right column, shortening so it ends above the size legend.

const config = {
  data: [
    {id: "Alpha", x: 4, y: 7, revenue: 120},
    {id: "Beta", x: 5, y: 2, revenue: 1450},
    {id: "Gamma", x: 6, y: 9, revenue: 640},
    {id: "Delta", x: 2, y: 4, revenue: 80},
    {id: "Epsilon", x: 8, y: 5, revenue: 2300},
    {id: "Zeta", x: 3, y: 8, revenue: 900},
    {id: "Eta", x: 7, y: 3, revenue: 310},
    {id: "Theta", x: 9, y: 8, revenue: 1800},
  ],
  groupBy: "id",
  legendPosition: "bottom",
  size: "revenue",
  sizeMax: 36,
  sizeMin: 4,
  x: "x",
  y: "y",
  colorScale: "y",
  colorScalePosition: "right",
  sizeLegendConfig: {
    title: "Revenue ($M)",
    values: [100, 1000, 2000],
    tickFormat: d => `$${d}M`,
  },
};

When the points leave a corner of the plot empty, the legend is drawn there, over a translucent box, instead of taking a margin. If the chart also sizes its points, the size legend gets the first try at that space and the legend goes back to its margin. Points that enclose an empty area never get a legend placed inside them.

const config = {
  data: [
    {id: "Alpha", group: "North", x: 1, y: 9},
    {id: "Beta", group: "North", x: 2, y: 10},
    {id: "Gamma", group: "North", x: 1.5, y: 8},
    {id: "Delta", group: "East", x: 9, y: 9},
    {id: "Epsilon", group: "East", x: 10, y: 10},
    {id: "Zeta", group: "East", x: 8.5, y: 8},
    {id: "Eta", group: "South", x: 1, y: 1},
    {id: "Theta", group: "South", x: 2, y: 2},
    {id: "Iota", group: "South", x: 2.5, y: 1.2},
  ],
  groupBy: ["group", "id"],
  x: "x",
  y: "y",
};

When color is a category that isn’t one of the groupBy levels, here each country’s point is colored by its region, the legend shows one entry per category, labelled by the category. Click an entry to hide every point in that region (click again to bring them back), shift+click it to show only that region, or hover it to highlight the region’s points. When color returns actual CSS colors there is no category to name, so the legend stays hidden.

Defines the mapping between data and shape. The value can be a String matching a key in each data point (default is "id"), or an accessor Function that returns a unique value for each data point. Additionally, an Array of these values may be provided if the visualization supports nested hierarchies.

Configuration

import {Plot} from "@d3plus/core";

Extends Viz.

activefalse | function

The active callback function for highlighting shapes.

annotationsunknownDefault unknown

Allows drawing custom shapes to be used as annotations in the provided x/y plot. This method accepts custom config objects for the Shape class, either a single config object or an array of config objects. Each config object requires an additional parameter, the "shape", which denotes which Shape sub-class to use (Rect, Line, etc).

Additionally, each config object can also contain an optional "layer" key, which defines whether the annotations will be displayed in "front" or in "back" of the primary visualization shapes. This value defaults to "back" if not present ("front" for callouts).

Three more kinds draw chart notes: "Callout" anchors wrapped text in a box at each data row's x/y (in data units, or plot-area fractions with xRef/yRef: "plot"), offset by dx/dy pixels and joined to its anchor by a connector ending in an arrowhead or dot (see CalloutAnnotation); "ReferenceLine" and "ReferenceBand" draw what referenceLines and referenceBands entries expand into. All annotations follow zoom and never respond to the pointer or keyboard.

axisPersistbooleanDefault unknown

Determines whether the x and y axes should have their scales persist while users filter the data, the timeline being the prime example (set this to true to make the axes stay consistent when the timeline changes).

backgroundConfigrecordDefault {duration: 0, fill: transparent}

A d3plus-shape configuration Object used for styling the background rectangle of the inner x/y plot (behind all of the shapes and gridlines).

baselinenumber

Starts the value axis (the x axis for horizontal charts) at a value: baseline(n) renders exactly like yDomain([n]) (or xDomain([n])). Bars, areas, and stems still grow from the chart's own 0 in the Plots that draw from one (such as BarChart, AreaPlot, Histogram, and Lollipop), so with baselineBreak on (their default) the axis breaks back to a 0 tick and bars run through the break, with its gap cut across them, and with it off the axis stretches down to 0. As with yDomain([n]), only n is pinned: the far end comes from the data and is rounded where the axis would round it with no domain set (left at the data when the axis config's rounding is "none"), and marks for values past n stop at the axis's edge. When every value sits at or below n, it ends the axis instead, like yDomain([undefined, n]). A bound given in yDomain/xDomain wins. Returns the chart's own baseline when none is set.

bufferboolean | recordDefault assign({}, defaultBuffers, {Bar: false, Line: false})

Determines whether or not to add additional padding at the ends of x or y scales. The most commone use for this is in Scatter Plots, so that the shapes do not appear directly on the axis itself. The value provided can either be true or false to toggle the behavior for all shape types, or a keyed Object for each shape type (ie. {Bar: false, Circle: true, Line: false}).

classNamestring | array.<string> | undefined

CSS classes added to the outermost element this chart or component draws into, next to its fixed d3plus classes, so page CSS can target it: a chart's root <svg class="d3plus-viz"> (its <canvas> with the Canvas renderer) and a standalone component's <svg>. Takes a space-separated string or an array. A new value replaces the classes the previous one added; unset adds none. Tooltips take their own tooltipConfig.className.

colorDefaultscolordefaultsconfig

Overrides the default colors used when assigning fills from data and choosing legible text colors: dark and light (the text colors picked for contrast against a background), missing (null/undefined values), on/off (true/false values), sequential (the anchor hue for magnitude ramps), and scale (the categorical palette, given as a d3 ordinal scale or an array of colors). Keys are merged into the current defaults, and a Viz passes its overrides down to the shapes and components it draws.

confidenceunknown

The confidence interval as an array of [lower, upper] bounds. Lines draw it as a shaded band; bars draw an error bar per bar, from the lower to the upper bound with a cap at each end (a stacked bar's bounds keep their distance from its value, measured from the bar's stacked end). Either bound may be false for a one-sided interval, and a row without a bound pinches the band onto its line. The value axis widens to fit the bounds, and tooltips list them (see confidenceConfig.tooltip). Pass false to turn the interval off.

Pass an array of bands, outermost first, to draw nested bands around each line (a fan): each band is a [lower, upper] pair or [lower, upper, label], or a {lower, upper, label} object, and confidenceConfig.bandOpacity shades them from the widest (lightest) to the narrowest (darkest). Tooltips list each band's range under its label ("Band 1", "Band 2", … when unlabeled), and bars draw the first band's error bar.

confidenceConfigrecordDefault
function
{fill: (d, i) => {
  const { Line, stroke } = this.schema.shapeConfig;
  const s = Line && Line.stroke !== undefined ? Line.stroke : stroke;
  return typeof s === "function" ? s(d, i) : s;
}, fillOpacity: 0.5}

Configuration object for shapes rendered as confidence intervals. A line's band is an Area, filled with the line's color at half opacity. A bar's error bar is a Path styled by stroke (default a shade darker than the bar), strokeWidth (default 2), strokeDasharray, strokeOpacity, and capWidth: the length of each end cap, in pixels or as a percentage string of the bar's thickness (default "50%"). Keys nested under Area or Bar apply only to that shape's interval. With several bands, bandOpacity sets how each band looks where it is the innermost band drawn: an array ramps from the outermost band to the innermost (default [0.15, 0.6]), a number gives every band that opacity, and either replaces fillOpacity. tooltip (default true) lists the bounds in tooltips: a "Lower Bound" and "Upper Bound" row for a single mark, and a range after each series' value in a shared tooltip; set it to false to leave them out. Accepted keys: any key the Area or Path shape takes at the top level, plus bandOpacity, capWidth, tooltip, Area (Area keys), and Bar (Path keys and capWidth); any other key logs a warning.

configd3plusconfig

Methods that correspond to the key/value pairs and returns this class.

crosshairConfigrecordDefault
function
{stroke: () => themed(this._theme, (t) => t.textMuted, colorGray.500), strokeDasharray: 4 3, strokeWidth: 1}

Paint for the shared tooltip's crosshair guide line (stroke, strokeWidth, strokeDasharray, strokeOpacity, …). Merged into the current config.

datastring | array.&lt;datapoint&gt; | object

The primary data array used to draw the visualization. The value passed should be an Array of objects or a String representing a filepath or URL to be loaded. The following filetypes are supported: csv, tsv, txt, and json.

If your data URL needs specific headers to be set, an Object with a "url" and "headers" (or any other fetch request option) may also be passed. An Object with any other key is a data row, not a request.

Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final array of obejcts to be used as the primary data array. For example, some JSON APIs return the headers split from the data values to save bandwidth. These would need be joined using a custom formatter.

If you would like to specify certain configuration options based on the yet-to-be-loaded data, you can also return a full config object from the data formatter (including the new data array as a key in the object).

To re-fetch a URL on an interval and redraw when its data changes, set dataPollingInterval; each poll runs the same formatter.

Defaults to an empty array ([]).

discreteCutoffnumberDefault unknown

When the width or height of the chart is less than or equal to this pixel value, the discrete axis will not be shown. This helps produce slick sparklines. Set this value to 0 to disable the behavior entirely.

facetstring | false | function

Splits the chart into small multiples: a grid of equally sized panels, one per distinct value of this data key or accessor, each drawing the chart for that value's rows. The panels share one legend, color scale, title, and timeline, color each series the same way, and hover, tooltips, and legend clicks apply across all of them. Pass false to draw a single chart. See facetConfig for the grid's layout and shared scales.

facetConfigfacetconfig

Configuration for small multiples (see facet), merged into the current config: - columns / rows: the grid's shape. Chosen by default to make the panels as large as the chart's shape allows. - padding: the space between panels, in pixels (default 20). - sort: panel order — "ascending" (default), "descending", "data" (first appearance), a comparator over facet values, or an Array of values. - scales: "shared" (default) gives every panel of a chart with axes the same x/y domains; "independent" fits each panel to its own rows. Funnel defaults to "independent" (each panel sized to its own widest stage); "shared" sizes every panel against the widest stage across all panels. PolarArea and RadialBar default to "independent" (each panel's rings and ticks fit its own values); "shared" gives every panel the same value domain. - axes: with shared scales, "outer" (default) labels the axes only along the grid's left and bottom edges; "all" labels every panel. An object sets each axis on its own, as in {x: "all", y: "outer"}: every panel labels its x axis, only the left column labels its y axis, and the panels' plot areas line up. BumpChart defaults to "all", and Marimekko labels its categories on every panel and its 0–100% share axis only along the outer edge, even with independent scales. - title: a (value, data) => string function for each panel's title, or false to hide panel titles. - titleConfig: TextBox config for the panel titles (fontSize, fontWeight, fontColor, textAnchor, padding, …).

fontFamilystring | array.&lt;string&gt;

The font family used throughout the visualization.

groupBystring | function | array.&lt;string | function&gt;

Defines the mapping between data and shape. The value can be a String matching a key in each data point (default is "id"), or an accessor Function that returns a unique value for each data point. Additionally, an Array of these values may be provided if the visualization supports nested hierarchies.

groupPaddingnumberDefault unknown

The pixel space between groups of bars.

highlightfalse | function

Persistently emphasizes the data points matching the given predicate: the matching marks keep their color while every other mark is de-emphasized to a neutral gray (the "emphasis" form — highlight one series, gray the rest). Unlike hover/active (transient, opacity-based), highlight is a standing state that survives pointer movement. Pass false to clear it.

hoverfalse | function

The hover callback function for highlighting shapes on mouseover.

labelConnectorConfigrecordDefault {strokeDasharray: 1 1}

The d3plus-shape config used on the Line shapes created to connect lineLabels to the end of their associated Line path.

lineMarkerConfigrecordDefault
function
{fill: (d, i) => colorAssign(this._id(d, i), linkedColorDefaults(this)), r: 3}

Shape config for the Circle shapes drawn by the lineMarkers method.

lineMarkersbooleanDefault unknown

Draws circle markers on each vertex of a Line.

localestring | object

The locale used for all text and number formatting. Supports the locales defined in d3plus-format. The locale can be a complex Object, a locale code (like "en-US"), or a 2-digit language code (like "en"). If a 2-digit code is provided, the "findLocale" function is used to identify the most approximate locale.

onstring

Event listener for the specified event typenames. Mirrors the core d3-selection behavior.

parentunknown

Parent config used by the wrapper.

renderfunction

Draws the visualization given the specified configuration.

rendererboolean | "svg" | "canvas"

Selects which @d3plus/render backend paints the visible output. "svg" = SvgRenderer (default), "canvas" = CanvasRenderer. Boolean arguments both normalize to "svg".

selectstring | htmlelement

The SVG container element as a d3 selector or DOM element. Defaults to undefined.

shapeConfigd3plusconfig

Configuration object with key/value pairs applied as method calls on each shape.

sizefalse | plotaccessorarg

Sets the size of bubbles to the given Number, data key, or function.

stackOffsetstring | stackoffsetfnDefault stackOffsetDiverging

Sets the vertical offset applied to stacked series. Accepts a named offset — "diverging" (default), "none", "expand", "silhouette", or "wiggle" — or a custom offset function. Unknown names warn and fall back to "diverging". If value is not specified, returns the current stack offset function.

stackOrderstackorderinputDefault stackOrderTotalDescending

Sets the order of stacked series, from the bottom of the stack upward. Accepts: - a named order: "descending" (default) / "ascending" by summed value, "key" / "keyReverse" alphabetically by series key, "none" / "data" for input order, or d3's "insideOut", "appearance", "reverse"; - an Array of series keys for an explicit order; - a value accessor, or a {value, order} config, to rank series by an aggregate of any data field.

Unknown named strings warn and fall back to "descending". If value is not specified, returns the current stack order.

thresholdnumber | function

The threshold value for bucketing small data points together, as a share of the total. On a stacked Plot, the series whose summed value across every position is under that share of the whole chart's total merge into one series, stacked on top. A bucket needs at least two items, and its tooltips list them. Off (0) by default on Plot charts.

thresholdKeystring | function

Accessor for the value used in the threshold algorithm. A stacked Plot defaults to its stacked value.

timestring | false | function

Accessor function or string key for the time dimension of each data point.

timelineDefaultstring | date | array.&lt;string | date&gt;

The starting time or range for the timeline. Can be a single Date/String, or an Array of 2 values representing the min and max.

totalstring | boolean | function

Accessor function or string key for the total value displayed in the visualization.

translatefunction

Defines how informational text strings should be displayed. By default, this function will try to find the string in question (which is the first argument provided to this function) inside of an internally managed translation Object. If you'd like to override to use custom text, simply pass this method your own custom formatting function.

trendLinetrendlinetype

Draws an automatic trend line fit to the plotted data: true (or "linear") for a least-squares line, or one of "exponential", "logarithmic", "power", or "polynomial". By default each series gets its own line in its color; see trendLineConfig for grouping, a confidence band, and styling. On a chart with a discrete axis, the line runs along that axis, fitting categories by their order. Set to false (the default) to remove.

trendLineConfigrecord

Options for the trend lines drawn by trendLine, merged into the current config: - group: "series" (default) fits one line per series, colored to match it; "all" fits a single line to every point. - order: the polynomial degree when trendLine is "polynomial" (default 2). - confidence: draws a confidence band around a linear fit (default false). - confidenceLevel: the band's confidence level (default 0.95). - confidenceConfig: Area shape config for the band (default {fillOpacity: 0.15}; fill defaults to the line color). - projection: extends each line past the end of its data, by a number of steps at the data's own spacing (e.g. 5 more years), or to an end value with {to: 2030} (default 0, off). The axis widens to fit, and a linear fit's band becomes a prediction interval that fans out over the projection. Hovering a projected step lists each series' projected value. Ignored on a category axis. - projectionConfig: Line shape config for the projected stretch, over the line's own styles (default {strokeDasharray: "2 4"}). - tooltip: shows the fitted equation and R² when hovering a line (default true). - Any other key (stroke, strokeWidth, strokeDasharray, …) styles the Line shape.

Stacked charts always fit one line to the stack totals.

xplotaccessorargDefault
function
d => d["x"]

Accessor function or string key for the x-axis value of each data point.

x2plotaccessorargDefault
function
d => d["x2"]

Accessor function or string key for the secondary x-axis value of each data point.

x2ConfigrecordDefault {}

A pass-through to the underlying Axis config used for the secondary x-axis. Includes additional functionality where passing "auto" as the value for the scale method will determine if the scale should be "linear" or "log" based on the provided data.

xConfigrecordDefault
function
{gridConfig: {stroke: (d) => {
  if (this.schema.discrete?.charAt(0) === "x" || this._swarm?.cross === "x") return "transparent";
  const range = this._xAxis.range();
  const position = this._xAxis._getPosition.bind(this._xAxis)(d.id);
  if (range[0] === position) return "transparent";
  return chartGridline(this);
}}}

A pass-through to the underlying Axis config used for the x-axis. Includes additional functionality where passing "auto" as the value for the scale method will determine if the scale should be "linear" or "log" based on the provided data.

yplotaccessorargDefault
function
d => d["y"]

Accessor function or string key for the y-axis value of each data point.

y2plotaccessorargDefault
function
d => d["y2"]

Accessor function or string key for the secondary y-axis value of each data point.

y2ConfigrecordDefault {}

A pass-through to the underlying Axis config used for the secondary y-axis. Includes additional functionality where passing "auto" as the value for the scale method will determine if the scale should be "linear" or "log" based on the provided data.

yConfigrecordDefault
function
{gridConfig: {stroke: (d) => {
  if (this.schema.discrete?.charAt(0) === "y" || this._swarm?.cross === "y") return "transparent";
  const range = this._yAxis.range();
  const position = this._yAxis._getPosition.bind(this._yAxis)(d.id);
  if (range[range.length - 1] === position) return "transparent";
  return chartGridline(this);
}}}

A pass-through to the underlying Axis config used for the y-axis. Includes additional functionality where passing "auto" as the value for the scale method will determine if the scale should be "linear" or "log" based on the provided data.

Note: If a "domain" array is passed to the y-axis config, it will be reversed.