Product comparison matrix
Products side by side, feature by feature, the best of each row marked. Good for shops, buying guides and product pages.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
import 'nervure/themes';
const spec = {
type: 'specmatrix',
format: { currency: 'EUR' },
products: [
{ name: 'Model S', price: 350, rating: 3.9 },
{ name: 'Model M', price: 470, rating: 4.2, badge: 'Popular' },
{ name: 'Model L', price: 670, rating: 4.1 },
],
features: [
{ name: 'Battery', values: [10, 16, 19], unit: 'h' },
{ name: 'Weight', values: [189, 236, 288], unit: 'g', better: 'low' },
{ name: 'Screen', values: [6.1, 6.4, 6.9], unit: '″' },
{ name: 'Storage', values: [128, 256, 512], unit: 'GB' },
{ name: 'Water resistant', values: [false, true, true] },
{ name: 'Wireless charging', values: [false, false, true] },
{ name: 'Colours', values: ['3', '5', '2'] },
{ name: 'Warranty', values: [1, 2, 2], unit: 'yr' },
],
};
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 specmatrix takes:
/** Products side by side, feature by feature, the best of each row marked. */
interface SpecMatrixSpec extends Base {
type: 'specmatrix';
products: { name: string; price?: number; rating?: number; badge?: string; color?: string }[];
features: {
name: string;
/** One value for each product: a number, yes or no, or a text. */
values: (number | boolean | string | null)[];
/** For numbers: which end is best. `high` by default. */
better?: 'high' | 'low';
unit?: string;
}[];
onItemClick?: (name: string) => void;
}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