Skip to content

Box Plot · Violin ​

A box plot summarizes the distribution of raw samples per category: quartiles, whiskers, outliers and an optional mean. With violin, each group is drawn as a kernel density shape instead. The engine computes every statistic in O(n) per group and does not keep the raw samples.

Live example

Basic usage ​

ts
import { Charturbo } from 'charturbo';

const canvas = document.querySelector('canvas')!;
const sdk = await Charturbo.create(canvas);

sdk.renderBoxPlot(
  {
    categories: ['Mon', 'Tue', 'Wed'],
    series: [
      { name: 'Control', values: [monF32, tueF32, wedF32] }, // raw samples per category
      { name: 'Treated', values: [a, b, c] },
    ],
  },
  {
    title: 'Response time',
    axes: { y: { title: 'ms' } },
    whiskers: 'tukey',
    showOutliers: true,
    showMean: true,
  }
);
sdk.enableNodeInteractions(canvas, { autoRender: true });
sdk.render();
ts
renderBoxPlot(
  data: BoxPlotData,
  options?: BoxPlotOptions
): { boxCount: number; seriesCount: number; categoryCount: number; sampleCount: number }

Data point ids: box = series * categories + category; outlier ids follow the boxes.

Data format ​

BoxPlotData:

FieldTypeDescription
categoriesstring[]Category (x axis) labels.
series[].namestringSeries name.
series[].values(Float32Array | number[] | null | undefined)[]One raw sample array per category. Empty or missing = no box.
series[].colorColorInputDefault: theme palette in series order.

Several series are laid out side by side in each category, like grouped bars.

Options ​

BoxPlotOptions:

OptionTypeDefaultDescription
whiskers'tukey' | 'minmax' | [number, number]'tukey''tukey': last sample within iqrFactor × IQR of the quartiles. 'minmax': data extremes (no outliers). [p0, p1]: percentiles 0–100, e.g. [5, 95].
iqrFactornumber1.5Tukey IQR factor.
showOutliersbooleantrueOutliers as points (box mode).
maxOutliersnumber10000Drawn outliers per group. More are sampled evenly; the count stays exact.
showMeanbooleanfalseMean as a hollow dot.
outlinebooleanfalseBoxes as outlines instead of filled bars.
violinboolean | BoxPlotViolinOptionsfalseViolins (KDE) instead of boxes.
colorsColorInput[]theme paletteSeries colors.
titlestring—Chart title.
descriptionstring—Accessible name of the canvas.
valueLabelstring'Value' (localized)Tooltip and table name of the values.
axes{ x?: ChartAxisOptions; y?: ChartAxisOptions }—Axis titles and formats.
legendChartLegendOptions | booleanshown for 2+ seriesSeries legend with toggle and emphasis.
groupGapnumber0.3Empty fraction of each category slot between groups.
boxGapnumber2CSS px gap between the boxes of a group.
cornerRadiusnumber4Rounded box ends in CSS px.
whiskerWidthnumber1.5Whisker / outline stroke width in CSS px.
outlierRadiusnumber3Outlier dot radius in CSS px.
hoverChartHoverStyle—Hover style.
showBackdropGridbooleantrueHorizontal gridlines and baseline.
gridChartGridStyle—Grid style.
paddingChartPaddingOptionsautoPlot margins in CSS px.
animationChartAnimationInputSDK settingEnter / update animation.
widthnumber164World width of the plot.
heightnumber80World height of the plot.

Violin ​

ts
sdk.renderBoxPlot(data, { violin: { showBox: true, scale: 'area', opacity: 0.3 } });

BoxPlotViolinOptions:

FieldTypeDefaultDescription
bandwidthnumberSilverman's rule per groupGaussian kernel bandwidth in data units.
showBoxbooleantrueInner box (whisker line, IQR bar, median dot). false = median line only.
scale'area' | 'width''area''area': every violin encloses the same area. 'width': each violin reaches full width.
opacitynumber0.3Fill opacity of the violin body.

The KDE is evaluated on 128 points after linear binning onto a fine grid: O(n + grid), not O(n · grid), even for 1,000,000 samples. Violins draw no outlier points.

Statistics ​

  • Quartiles use selection (select_nth_unstable), not sorting, and match numpy's linear interpolation.
  • One more pass computes the whisker ends, the outlier count and the standard deviation.
  • Outliers beyond maxOutliers are sampled at even, deterministic steps; the minimum and maximum are kept.

Hover and legend ​

  • Hovering a box shows min, Q1, median, Q3, max, mean, whiskers, n and the outlier count. Hovering an outlier shows its value. ctx.box holds these statistics.
  • The legend (2+ series) toggles and emphasizes series. More than 8 series fold into "Other".
  • Box plots have no brush and no zoom.

See Tooltips & Hover.

Accessibility ​

The chart provides a summary, a data table and CSV with one row per category × series, and keyboard navigation (left / right = category, up / down = series). See Accessibility.

Updating data ​

Call renderBoxPlot again with the new samples.

Frameworks ​

tsx
<CharturboChart type="box" data={{ categories, series }} options={{ violin: true }} />

See also ​

MIT License