Diverging bar chart
Bars that go left or right of a middle. Good for gains and losses, above and below a target, agree and disagree.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'diverging',
below: 'Fewer',
above: 'More',
sort: true,
data: [
{ name: 'Kairouan', value: -21 },
{ name: 'Gabes', value: -21 },
{ name: 'Sousse', value: 50 },
{ name: 'Mahdia', value: -38 },
{ name: 'Djerba', value: 19 },
{ name: 'Sfax', value: -40 },
{ name: 'Bizerte', value: -1 },
{ name: 'Tunis', value: -18 },
],
};
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 diverging takes:
/** Bars that go left or right of a middle. */
interface DivergingSpec extends Base {
type: 'diverging';
data: { name: string; value: number; color?: string }[];
/** Where the bars start, 0 by default. */
centre?: number;
/** Names of the two sides, shown in the legend. */
below?: string;
above?: string;
/** Colours of the two sides. */
colors?: [string, string];
/** From the largest to the smallest. */
sort?: 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