@vx/grid

The @vx/grid package lets you create gridlines for charts. <GridRows /> render horizontally, <GridColumns /> render vertically, or you can use a <Grid /> to get them both at once!

Usage

import { Grid } from '@vx/grid';
// or
// import * as Grid from '@vx/grid';
// <Grid.Grid />

const grid = (
  <Grid
    xScale={xScale}
    yScale={yScale}
    width={xMax}
    height={yMax}
    numTicksRows={numTicksForHeight(height)}
    numTicksColumns={numTicksForWidth(width)}
  />
);

Installation

npm install --save @vx/grid

Examples

Components

APIs

#<GridRows />

# GridRows.scaleScalerequired

@vx/scale or d3-scale object used to convert value to position.

# GridRows.widthnumberrequired

Total width of each grid row line.

# GridRows.children((props: { lines: GridLines; }) => ReactNode) | undefinedoptional

Optionally override rendering of grid lines.

# GridRows.classNamestring | undefinedoptional

classname to apply to line group element.

# GridRows.fillstring | undefinedoptional

fill color applied to line element.

# GridRows.fromPoint | undefinedoptional

Starting x,y point of the line.

# GridRows.innerRef((instance: SVGLineElement | null) => void) | RefObject<SVGLineElement> | null | undefinedoptional

reference to line element.

# GridRows.leftnumber | undefinedoptional

Left offset to apply to glyph g element container.

Default 0

# GridRows.lineStyleCSSProperties | undefinedoptional

Styles to apply as grid line style.

# GridRows.numTicksnumber | undefinedoptional

Approximate number of grid lines. Approximate due to d3 alogrithm, specify tickValues for precise control.

Default 10

# GridRows.offsetnumber | undefinedoptional

Pixel offset to apply as a translation (y- for Rows, x- for Columns) to each grid lines.

# GridRows.strokestring | undefinedoptional

Grid line stroke color.

Default #eaf0f6

# GridRows.strokeDasharraystring | undefinedoptional

Grid line stroke-dasharray attribute.

# GridRows.strokeWidthstring | number | undefinedoptional

Grid line stroke thickness.

Default 1

# GridRows.tickValuesParameters<Scale>[0][] | undefinedoptional

Exact values used to generate grid lines using scale. Overrides numTicks if specified.

# GridRows.toPoint | undefinedoptional

Ending x,y point of the line.

# GridRows.topnumber | undefinedoptional

Top offset to apply to glyph g element container.

Default 0

#<GridColumns />

# GridColumns.heightnumberrequired

Total height of each grid column line.

# GridColumns.scaleScalerequired

@vx/scale or d3-scale object used to convert value to position.

# GridColumns.children((props: { lines: GridLines; }) => ReactNode) | undefinedoptional

Optionally override rendering of grid lines.

# GridColumns.classNamestring | undefinedoptional

classname to apply to line group element.

# GridColumns.fillstring | undefinedoptional

fill color applied to line element.

# GridColumns.fromPoint | undefinedoptional

Starting x,y point of the line.

# GridColumns.innerRef((instance: SVGLineElement | null) => void) | RefObject<SVGLineElement> | null | undefinedoptional

reference to line element.

# GridColumns.leftnumber | undefinedoptional

Left offset to apply to glyph g element container.

Default 0

# GridColumns.lineStyleCSSProperties | undefinedoptional

Styles to apply as grid line style.

# GridColumns.numTicksnumber | undefinedoptional

Approximate number of grid lines. Approximate due to d3 alogrithm, specify tickValues for precise control.

Default 10

# GridColumns.offsetnumber | undefinedoptional

Pixel offset to apply as a translation (y- for Rows, x- for Columns) to each grid lines.

# GridColumns.strokestring | undefinedoptional

Grid line stroke color.

Default #eaf0f6

# GridColumns.strokeDasharraystring | undefinedoptional

Grid line stroke-dasharray attribute.

# GridColumns.strokeWidthstring | number | undefinedoptional

Grid line stroke thickness.

Default 1

# GridColumns.tickValuesParameters<Scale>[0][] | undefinedoptional

Exact values used to generate grid lines using scale. Overrides numTicks if specified.

# GridColumns.toPoint | undefinedoptional

Ending x,y point of the line.

# GridColumns.topnumber | undefinedoptional

Top offset to apply to glyph g element container.

Default 0

#<Grid />

# Grid.xScaleXScalerequired

@vx/scale or d3-scale object used to map from ScaleInput to x-coordinates (GridColumns).

# Grid.yScaleYScalerequired

@vx/scale or d3-scale object used to map from ScaleInput to y-coordinates (GridRows).

# Grid.classNamestring | undefinedoptional

classname to apply to line group element.

# Grid.columnLineStyleCSSProperties | undefinedoptional

Style object to apply to GridColumns.

# Grid.columnTickValuesParameters<XScale>[0][] | undefinedoptional

Exact values to be used for GridColumns lines, passed to xScale. Use this if you need precise control over GridColumns values.

# Grid.fillstring | undefinedoptional

fill color applied to line element.

# Grid.innerRef((instance: SVGLineElement | null) => void) | RefObject<SVGLineElement> | null | undefinedoptional

reference to line element.

# Grid.leftnumber | undefinedoptional

Left offset to apply to glyph g element container.

# Grid.numTicksColumnsnumber | undefinedoptional

Approximate number of column gridlines.

# Grid.numTicksRowsnumber | undefinedoptional

Approximate number of row gridlines.

# Grid.rowLineStyleCSSProperties | undefinedoptional

Style object to apply to GridRows.

# Grid.rowTickValuesParameters<YScale>[0][] | undefinedoptional

Exact values to be used for GridRows lines, passed to yScale. Use this if you need precise control over GridRows values.

# Grid.strokestring | undefinedoptional

Grid line stroke color.

# Grid.strokeDasharraystring | undefinedoptional

Grid line stroke-dasharray attribute.

# Grid.strokeWidthstring | number | undefinedoptional

Grid line stroke thickness.

# Grid.topnumber | undefinedoptional

Top offset to apply to glyph g element container.

# Grid.widthnumberoptional

Total width of each grid row line.

# Grid.xOffsetnumber | undefinedoptional

Pixel offset to apply as an x-translation to each GridColumns line.

# Grid.yOffsetnumber | undefinedoptional

Pixel offset to apply as an y-translation to each GridRows line.