3D histogram
Columns on a grid of two kinds of categories, as high as their count and coloured by it. Good for how a population spreads over two groupings: age and income, size and price.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
import 'nervure/3d';
const spec = {
type: 'histogram3d',
x: ['18-24', '25-34', '35-44', '45-54', '55-64', '65+'],
y: ['< 20k', '20-40k', '40-60k', '60-80k', '> 80k'],
titles: { x: 'Age', y: 'Income', z: 'People' },
z: [
[22, 34, 41, 46, 30, 16],
[33, 55, 68, 68, 50, 27],
[42, 55, 86, 77, 61, 31],
[28, 58, 65, 71, 56, 31],
[26, 31, 45, 47, 41, 17],
],
};
export default function Example() {
return <Chart spec={spec} style={{ height: 340 }} />;
}Or import this chart alone: what each import weighs.
Options
Beside the fields shared by every chart (title, format, heading, export…), type histogram3d takes:
/** Columns on a grid of two kinds of categories, as high as `z[row][column]`, coloured by height. */
interface Histogram3DSpec extends Base3D {
type: 'histogram3d';
/** One row for each `y`, one value for each `x`; null leaves the cell empty. */
z: (number | null)[][];
/** Names of the columns of `z`, along the width. */
x?: string[];
/** Names of the rows of `z`, along the depth. */
y?: string[];
/** Colours from the lowest to the highest value. */
colors?: string[];
/** Share of a cell taken by its column, from 0.2 to 1: 0.7 by default. */
width?: number;
titles?: { x?: string; y?: string; z?: string };
}
interface Base3D extends Base {
/** Where the eye stands, in degrees: `azimuth` turns around the vertical axis, `elevation` rises from the floor (0) to straight above (90). */
view?: { azimuth?: number; elevation?: number };
/** Drag the chart, or focus its turn button and use the arrow keys, to turn the view. Home on the button goes back to `view`. */
rotate?: boolean;
}Style it
- Colours:
theme.palette,chart.setColor(name, colour), or--nervure-palettein your CSS. More - Marks:
[data-series="name"], parts:[data-part="axes"],legend,series. What you change is kept in exports. - Movement:
animation: falsedraws at once. More - Files:
chart.download('png'),svg,csv. More