OrbChartsOrbCharts

CategoricalPlot

CategoricalPlot is the core Plugin for the series data format. It presents a categorical bubble chart with one "category axis" and one "value axis": at each category position it stacks bubbles whose size corresponds to the value.

Data format: series

Supported charts

  • Categorical Bubble — RaisedBubble Layer

Quick start

A minimal configuration draws a categorical bubble chart. CategoricalPlot shows three Layers by default: RaisedBubble, CategoryAxis, and ValueAxis:

import { OrbCharts } from '@orbcharts/core'
import type { RawData } from '@orbcharts/core'
import { CategoricalPlot, Tooltip, Legend } from '@orbcharts/plugin-basic'
 
const data: RawData = [
  { series: 'A', category: '0', value: 5 },
  { series: 'A', category: '1', value: 8 },
  { series: 'B', category: '0', value: 3 },
]
 
const chart = new OrbCharts(document.querySelector('#chart')!, {
  data,
  plugins: [
    new CategoricalPlot({ RaisedBubble: {}, 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 series data has series, category, and value: category maps to the category axis, value determines the bubble size and maps to the value axis, and series is used for grouping and coloring.

Chart examples

Categorical Bubble

new CategoricalPlot({ RaisedBubble: {}, CategoryAxis: {}, ValueAxis: {} })

RaisedBubble draws a bubble sized by value at each category position, alongside the category and value axes. Add CategoryGuide to show guide lines and CategoryZoom to enable zooming along the category axis.

Tip: Pair with Legend and Tooltip for interactivity, added the same way as in GridPlot.

How layer visibility works

CategoricalPlot 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 CategoricalPlot()), it shows RaisedBubble, CategoryAxis, ValueAxis by default (a categorical bubble chart). You can also switch Layers dynamically with show/hide/showOnly after creation.

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

Plugin parameters

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

ParameterTypeDefaultDescription
valueAxisPosition'left' | 'right''left'Which side the value axis is on
categoryScaleCategoryAxissee belowCategory axis settings
valueScaleValueAxissee belowValue axis settings
datasetIndexnumber0Which dataset to use when data is multi-dataset
stylesGraphicStylespadding is { 20, 60, 80, 60 }Shared visual styles (see Plugin API)
containerContainersingle chartMulti-chart layout (see Plugin API)
visibleFilterVisibleFilter<'series'>() => 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 CategoricalPlot's default differences are noted here (styles.padding defaults to { top: 20, right: 60, bottom: 80, left: 60 }, and transitionDuration defaults to 200).

categoryScale (CategoryAxis)

PropertyTypeDefaultDescription
scaleDomain[number, number | 'max'][0, 'max']Category index range
scalePaddingnumber0.5Spacing between categories

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

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.

RaisedBubble

ParameterTypeDefaultDescription
sizeAdjustnumber0.8Bubble size adjustment factor
arcScaleType'radius' | 'area''area'How values map (radius or area)
valueLinearOpacity[number, number][0.5, 1]Opacity range based on the value
showZeroValuebooleanfalseWhether to show bubbles with a value of 0

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

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
labelTextFormatstring | ((text) => string)text => textLabel text formatter
labelPaddingnumber20Label padding
labelRotatenumber0Label rotation angle

CategoryZoom

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

new CategoricalPlot({ RaisedBubble: {}, CategoryAxis: {}, ValueAxis: {}, CategoryZoom: {} })

Full TypeScript interface

interface CategoricalPlotPluginParams {
  styles: GraphicStyles
  visibleFilter: VisibleFilter<'series'>
  container: Container
  valueAxisPosition: 'left' | 'right'
  categoryScale: CategoryAxis
  valueScale: ValueAxis
  datasetIndex: number
}
 
interface CategoricalPlotAllLayerParams {
  RaisedBubble: CategoricalPlotRaisedBubbleParams
  CategoryAxis: CategoricalPlotCategoryAxisParams
  CategoryZoom: CategoricalPlotCategoryZoomParams
  ValueAxis: CategoricalPlotValueAxisParams
  CategoryGuide: CategoricalPlotCategoryGuideParams
}
 
// The constructor accepts a DeepPartial of both (Layer names alongside Plugin params)
new CategoricalPlot(params?: DeepPartial<CategoricalPlotPluginParams & CategoricalPlotAllLayerParams>)