Skip to content

Line

Creates SVG lines based on an array of data.

Points sharing the same id connect into one continuous line, with x/y placing each vertex.

const config = {
  data: [
    {id: "series", x: 50, y: 220},
    {id: "series", x: 160, y: 120},
    {id: "series", x: 270, y: 180},
    {id: "series", x: 380, y: 70},
    {id: "series", x: 490, y: 150},
    {id: "series", x: 600, y: 60},
  ],
  id: "id",
  x: "x",
  y: "y",
};

Points are grouped into lines by id, so three ids give three lines from one data array; stroke and strokeWidth read per-datum values like any other accessor.

const config = {
  data: [
    {id: "a", x: 50, y: 220, color: "#3a7ca5"},
    {id: "a", x: 230, y: 120, color: "#3a7ca5"},
    {id: "a", x: 410, y: 180, color: "#3a7ca5"},
    {id: "a", x: 590, y: 70, color: "#3a7ca5"},
    {id: "b", x: 50, y: 100, color: "#cc4b4b"},
    {id: "b", x: 230, y: 200, color: "#cc4b4b"},
    {id: "b", x: 410, y: 90, color: "#cc4b4b"},
    {id: "b", x: 590, y: 160, color: "#cc4b4b"},
    {id: "c", x: 50, y: 160, color: "#5d6d7e"},
    {id: "c", x: 230, y: 60, color: "#5d6d7e"},
    {id: "c", x: 410, y: 240, color: "#5d6d7e"},
    {id: "c", x: 590, y: 200, color: "#5d6d7e"},
  ],
  id: "id",
  stroke: d => d.color,
  strokeWidth: 3,
  x: "x",
  y: "y",
};

curve names a d3 curve: linear (the default) joins points with straight segments, monotoneX smooths between them without overshooting, and step, basis, cardinal, and the rest are available by name.

const config = {
  data: [
    {id: "series", x: 50, y: 220},
    {id: "series", x: 160, y: 120},
    {id: "series", x: 270, y: 180},
    {id: "series", x: 380, y: 70},
    {id: "series", x: 490, y: 150},
    {id: "series", x: 600, y: 60},
  ],
  curve: "monotoneX",
  id: "id",
  strokeWidth: 3,
  x: "x",
  y: "y",
};

Configuration

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

Extends Shape → BaseClass.

activefunction | null

The active callback function for highlighting shapes.

activeStylerecord

The style to apply to active shapes.

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.

configpartial

Narrowed .config() for Line. Inherited surface from BaseClass.config(); the override exists only to surface per-shape keys (e.g. width/height for Rect) in autocomplete + type checks.

dataarray.&lt;datapoint&gt;

The data array used to create shapes. A shape will be drawn for each object in the array.

hoverfunction | null

The hover callback function for highlighting shapes on mouseover.

hoverStylerecord

The style to apply to hovered shapes.

labelConfigrecord

A pass-through to the config method of the TextBox class used to create a shape's labels.

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.

selectstring | htmlelement | svgelement | null

The SVG container element as a d3 selector or DOM element.

shapeConfigd3plusconfig

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

sortfunction | null

A comparator function used to sort shapes for layering order.

textureDefaultrecord

A series of global texture methods to be used for all textures (ie. {stroke: "darkorange", strokeWidth: 2}).

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.