Skip to content

Star ratings ​

The average in stars, how many gave each number, and scores by aspect. Good for reviews on product pages and in shop reports.

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: 'ratings',
  counts: [707, 278, 73, 39, 37],
  aspects: [
    { name: 'Quality', value: 3.9 },
    { name: 'Value for money', value: 4 },
    { name: 'Delivery', value: 4.2 },
  ],
};

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 ratings takes:

/** Reviews of a product: the average in stars, how many gave each, and scores by aspect. */
interface RatingsSpec extends Base {
  type: 'ratings';
  /** Reviews with 5, 4, 3, 2 and 1 star, in that order. */
  counts: number[];
  /** Scores out of 5 by aspect: quality, price, delivery. */
  aspects?: { name: string; value: number }[];
}

Style it

  • Colours: theme.palette, chart.setColor(name, colour), or --nervure-palette in your CSS. More
  • Marks: [data-series="name"], parts: [data-part="axes"], legend, series. What you change is kept in exports.
  • Movement: animation: false draws at once. More
  • Files: chart.download('png'), svg, csv. More

Close to it