OrbChartsOrbCharts

GridPlot

GridPlot is the core Plugin for the grid data format. It has a "category axis" and a "value axis", and can draw several common chart types by switching its internal Layers.

Data format: grid

Supported charts

GridPlot renders different charts through different Layer combinations:

Quick start

A minimal configuration draws a bar chart. GridPlot shows three Layers by default: Bar, CategoryAxis, and ValueAxis:

import { OrbCharts } from '@orbcharts/core'
import type { RawData } from '@orbcharts/core'
import { GridPlot, Tooltip, Legend } from '@orbcharts/plugin-basic'
 
const data: RawData = [
  { series: 'A', category: 'category1', value: 30 },
  { series: 'A', category: 'category2', value: 20 },
  { series: 'A', category: 'category3', value: 45 },
  { series: 'B', category: 'category1', value: 70 },
  { series: 'B', category: 'category2', value: 80 },
  { series: 'B', category: 'category3', value: 90 },
]
 
const chart = new OrbCharts(document.querySelector('#chart')!, {
  data,
  plugins: [
    new GridPlot({ Bar: {}, CategoryAxis: {}, ValueAxis: {} }),
    new Tooltip(),
    new Legend(),
  ],
})
 
// chart.destroy()

Tip: The chart fills its container by default, so set a width and height on the #chart container. See Core Concepts.

Each record in this grid data has series, category, and value: category maps to the category axis, value maps to the value axis, and series is used for grouping and coloring.

How layer visibility works

GridPlot is composed of multiple Layers, and the Layer names you list in the params are the Layers that get shown. If you specify no Layers (new GridPlot()), it shows Bar, CategoryAxis, ValueAxis by default (a bar chart). You can also switch Layers dynamically with show/hide/showOnly after creation.

new GridPlot({ Bar: {}, CategoryAxis: {}, ValueAxis: {} })   // bar chart
new GridPlot({ Line: {}, CategoryAxis: {}, ValueAxis: {} })  // line chart

Tip: Layer visibility and the show/hide/showOnly/toggle methods are common to all Plugins. See Plugin API for the full explanation.

Chart examples

All examples below use the same grid data—just swap the Layer to change the chart type.

Bar Chart

new GridPlot({ Bar: {}, CategoryAxis: {}, ValueAxis: {} })

The most basic chart. Bar draws the bars, alongside the category and value axes.

Line Chart

new GridPlot({ Line: {}, Point: {}, CategoryAxis: {}, ValueAxis: {} })

Line draws the line; add Point to show dots at each data point.

Area Chart

new GridPlot({ LineArea: {}, CategoryAxis: {}, ValueAxis: {} })

LineArea fills a gradient area below the line—good for showing volume or trends.

Stacked Bar

new GridPlot({ StackedBar: {}, CategoryAxis: {}, StackedValueAxis: {} })

StackedBar stacks the values of each series within the same category, paired with StackedValueAxis to show the stacked value axis.

Triangle Bar

new GridPlot({ TriangleBar: {}, CategoryAxis: {}, ValueAxis: {} })

TriangleBar renders triangular gradient bars, often used for funnels or to emphasize a descending effect.

Plugin parameters

These parameters affect the whole GridPlot's behavior, listed alongside Layer names in the same params object:

ParameterTypeDefaultDescription
direction'bottom-up' | 'top-down' | 'left-right' | 'right-left''bottom-up'Chart direction (axis origin and growth direction)
separateSeriesbooleanfalseWhether to draw each series separately
datasetIndexnumber0Which dataset to use when data is multi-dataset
valueScaleValueAxissee belowValue axis settings
categoryScaleReversibleCategoryAxissee belowCategory axis settings
stylesGraphicStylespadding is { 20, 60, 80, 60 }Shared visual styles (see Plugin API)
containerContainersingle chartMulti-chart layout (see Plugin API)
visibleFilter(datum) => boolean | null() => trueFilter which data to show (see Plugin API)

Note: styles, container, and visibleFilter are shared by all chart Plugins; their structure and usage are documented centrally in Plugin API. Only GridPlot's default difference is noted here (styles.padding defaults to { top: 20, right: 60, bottom: 80, left: 60 }).

valueScale (ValueAxis)

PropertyTypeDefaultDescription
scaleDomain[number | 'min' | 'auto', number | 'max' | 'auto']['auto', 'auto']Value range
scaleRange[number, number][0, 0.9]Proportional range mapped to the plotting area

categoryScale (ReversibleCategoryAxis)

PropertyTypeDefaultDescription
reversebooleanfalseWhether to reverse the category order
scaleDomain[number, number | 'max'][0, 'max']Category index range
scalePaddingnumber0.5Spacing between categories

Layer parameters

Each Layer has its own parameters. The main parameters and defaults of each Layer are listed below.

About ColorType: color-related parameters use ColorType ('data', 'primary', etc.), mapping to the colors defined in the Theme. See Theme for the full explanation.

Bar

ParameterTypeDefaultDescription
barWidthnumber0Bar width (px); 0 means auto-calculated
barPaddingnumber1Spacing between bars
barGroupPaddingnumber40Spacing between groups
barRadiusnumber | booleanfalseCorner radius; false for none, or a number for the radius

Line

ParameterTypeDefaultDescription
lineCurvestring'curveLinear'Curve type (D3 curve name)
lineWidthnumber2Line width

LineArea

ParameterTypeDefaultDescription
lineCurvestring'curveLinear'Curve type (D3 curve name)
linearGradientOpacity[number, number][1, 0]Gradient opacity (start to end)

Point

ParameterTypeDefaultDescription
radiusnumber4Dot radius
fillColorTypeColorType'background'Fill color
strokeColorTypeColorType'data'Stroke color
strokeWidthnumber2Stroke width
onlyShowHighlightedbooleanfalseWhether to show only highlighted points

StackedBar

ParameterTypeDefaultDescription
barWidthnumber0Bar width (px); 0 means auto-calculated
barGroupPaddingnumber10Spacing between groups
barRadiusnumber | booleanfalseCorner radius

TriangleBar

ParameterTypeDefaultDescription
barWidthnumber0Bar width (px); 0 means auto-calculated
barPaddingnumber1Spacing between bars
barGroupPaddingnumber20Spacing between groups
linearGradientOpacity[number, number][1, 0]Gradient opacity (start to end)

CategoryAxis

ParameterTypeDefaultDescription
labelstring''Axis label
labelOffset[number, number][0, 0]Axis label offset
labelColorTypeColorType'primary'Axis label color
axisLineVisiblebooleantrueWhether to show the axis line
axisLineColorTypeColorType'primary'Axis line color
ticksnumber | null | 'all''all'Number of ticks
tickFormatstring | ((text) => string)text => textTick text formatter
tickLineVisiblebooleantrueWhether to show tick lines
tickPaddingnumber20Spacing between tick and text
tickFullLinebooleanfalseWhether to draw full gridlines
tickColorTypeColorType'secondary'Tick line color
tickTextRotatenumber0Tick text rotation angle
tickTextColorTypeColorType'primary'Tick text color

ValueAxis

ParameterTypeDefaultDescription
labelstring''Axis label
labelOffset[number, number][0, 0]Axis label offset
labelColorTypeColorType'primary'Axis label color
axisLineVisiblebooleanfalseWhether to show the axis line
ticksnumber | nullnullNumber of ticks (null for auto)
tickFormatstring | ((num) => string)thousands-separator formatterTick text formatter
tickLineVisiblebooleantrueWhether to show tick lines
tickPaddingnumber20Spacing between tick and text
tickFullLinebooleantrueWhether to draw full gridlines
tickColorTypeColorType'secondary'Tick line color
tickTextColorTypeColorType'primary'Tick text color
oppositebooleanfalseWhether to place the axis on the opposite side

StackedValueAxis

Same parameters as ValueAxis, used for stacked bar charts.

CategoryGuide

ParameterTypeDefaultDescription
showLinebooleantrueWhether to show the guide line
showLabelbooleantrueWhether to show the label
lineDashArraystring'3, 3'Dash pattern
lineColorTypeColorType'primary'Guide line color
labelColorTypeColorType'primary'Label background color
labelTextColorTypeColorType'background'Label text color
labelPaddingnumber20Label padding
labelRotatenumber0Label rotation angle

CategoryZoom

When enabled, allows zooming and panning along the category axis. This Layer has no extra parameters:

new GridPlot({ Bar: {}, CategoryAxis: {}, ValueAxis: {}, CategoryZoom: {} })

Full TypeScript interface

interface GridPlotPluginParams {
  styles: GraphicStyles
  visibleFilter: (datum: ModelDatumGrid) => boolean | null
  container: Container
  direction: 'bottom-up' | 'top-down' | 'left-right' | 'right-left'
  valueScale: ValueAxis
  categoryScale: ReversibleCategoryAxis
  separateSeries: boolean
  datasetIndex: number
}
 
interface GridPlotAllLayerParams {
  Bar: GridPlotBarParams
  Line: GridPlotLineParams
  LineArea: GridPlotLineAreaParams
  Point: GridPlotPointParams
  StackedBar: GridPlotStackedBarParams
  TriangleBar: GridPlotTriangleBarParams
  CategoryAxis: GridPlotCategoryAxisParams
  ValueAxis: GridPlotValueAxisParams
  StackedValueAxis: GridPlotStackedValueAxisParams
  CategoryGuide: GridPlotCategoryGuideParams
  CategoryZoom: GridPlotCategoryZoomParams
}
 
// The constructor accepts a DeepPartial of both (Layer names alongside Plugin params)
new GridPlot(params?: DeepPartial<GridPlotPluginParams & GridPlotAllLayerParams>)