Skip to main content

RadarChart

Overview​

The RadarChart component draws each series as a shape through its values on spokes, one spoke per category, to compare a few measures at a glance.

It wraps Recharts' RadarChart and comes from the @allxsmith/bestax-charts package, which the Charts guide shows how to install. You give it rows of data, the dataKey that holds each row's category, and the series to draw, and it draws them with Bulma's colors, a legend whose entries hide and show series, a tooltip in a Bulma box, and a data table screen readers read.


Import​

import { RadarChart } from '@allxsmith/bestax-charts';

Usage​

Basic Usage​

Each row of data is a category, a spoke of the chart, and each series names the key of the rows that holds its values. label names the chart; it's required, because it's what a screen reader announces.

function example() {
  const skills = [
    { skill: 'Speed', ana: 82, ben: 61 },
    { skill: 'Strength', ana: 54, ben: 88 },
    { skill: 'Stamina', ana: 76, ben: 72 },
    { skill: 'Agility', ana: 90, ben: 48 },
    { skill: 'Accuracy', ana: 68, ben: 79 },
  ];

  return (
    <RadarChart
      label="Player skills"
      data={skills}
      dataKey="skill"
      series={[
        { name: 'ana', label: 'Ana', color: 'primary' },
        { name: 'ben', label: 'Ben', color: 'info' },
      ]}
      angleAxisLabel="Skill"
      hasLegend
    />
  );
}

angleAxisLabel says what the categories are. The chart draws no title for it; it heads the data table's first column, which dataKey heads without one.

Grid and Axes​

grid shapes the grid: polygon rings with a corner at each category (the default), round circle rings, or none. hasRadiusAxis draws the value scale up from the center to the first category, and hasAngleAxis={false} leaves out the categories written around the chart.

function example() {
  const skills = [
    { skill: 'Speed', ana: 82 },
    { skill: 'Strength', ana: 54 },
    { skill: 'Stamina', ana: 76 },
    { skill: 'Agility', ana: 90 },
    { skill: 'Accuracy', ana: 68 },
  ];
  const series = [{ name: 'ana', label: 'Ana', color: 'primary' }];

  return (
    <Columns>
      <Column>
        <RadarChart
          label="Polygon grid with a scale"
          showLabel
          data={skills}
          dataKey="skill"
          series={series}
          hasRadiusAxis
          radiusAxisProps={{ domain: [0, 100] }}
          height={260}
        />
      </Column>
      <Column>
        <RadarChart
          label="Round grid"
          showLabel
          grid="circle"
          data={skills}
          dataKey="skill"
          series={series}
          height={260}
        />
      </Column>
    </Columns>
  );
}

Dots and Labels​

hasDots draws a dot at each value, and showLabels writes each value beside its point.

function example() {
  const week = [
    { day: 'Mon', steps: 6200 },
    { day: 'Tue', steps: 8400 },
    { day: 'Wed', steps: 7100 },
    { day: 'Thu', steps: 9800 },
    { day: 'Fri', steps: 5600 },
    { day: 'Sat', steps: 11200 },
    { day: 'Sun', steps: 4300 },
  ];

  return (
    <RadarChart
      label="Steps by day"
      data={week}
      dataKey="day"
      series={[{ name: 'steps', label: 'Steps', color: 'success' }]}
      hasDots
      showLabels
    />
  );
}

Fills and Dashes​

fillOpacity sets how opaque every series' fill is, from 0 for an outline alone to 1, and a series' own fillOpacity wins over it. A series' strokeDasharray dashes its outline, which tells it apart by more than color; say in its label that it's the dashed one, since the legend shows only the color.

function example() {
  const budget = [
    { area: 'Housing', planned: 1400, spent: 1450 },
    { area: 'Food', planned: 600, spent: 720 },
    { area: 'Transport', planned: 300, spent: 260 },
    { area: 'Leisure', planned: 250, spent: 410 },
    { area: 'Savings', planned: 500, spent: 350 },
  ];

  return (
    <RadarChart
      label="Budget, planned and spent"
      data={budget}
      dataKey="area"
      angleAxisLabel="Area"
      series={[
        {
          name: 'planned',
          label: 'Planned (dashed)',
          color: 'grey',
          fillOpacity: 0,
          strokeDasharray: '6 4',
        },
        { name: 'spent', label: 'Spent', color: 'danger' },
      ]}
      fillOpacity={0.4}
      hasDots
      hasLegend
    />
  );
}

Legend and Hidden Series​

hasLegend draws a legend below the chart, or above it with legendPosition="top". Each entry is a toggle button that hides or shows its series. The chart keeps that state itself, starting from defaultHiddenSeries, or you hold it with hiddenSeries and onHiddenSeriesChange.

function example() {
  const skills = [
    { skill: 'Speed', ana: 82, ben: 61, cam: 70 },
    { skill: 'Strength', ana: 54, ben: 88, cam: 66 },
    { skill: 'Stamina', ana: 76, ben: 72, cam: 90 },
    { skill: 'Agility', ana: 90, ben: 48, cam: 74 },
  ];
  const [hidden, setHidden] = useState(['cam']);

  return (
    <>
      <Buttons mb="3">
        <Button size="small" onClick={() => setHidden([])}>
          Show all
        </Button>
      </Buttons>
      <RadarChart
        label="Player skills"
        data={skills}
        dataKey="skill"
        series={[
          { name: 'ana', label: 'Ana', color: 'primary' },
          { name: 'ben', label: 'Ben', color: 'info' },
          { name: 'cam', label: 'Cam', color: 'warning' },
        ]}
        hasLegend
        legendPosition="top"
        hiddenSeries={hidden}
        onHiddenSeriesChange={setHidden}
      />
    </>
  );
}

Formatting Values​

Values are written as useNumberFormat writes a number, in the LocaleProvider's locale. valueFormatter writes them your way instead, on the value scale, in the tooltip, on the labels and in the data table, and unit is written after each one.

function example() {
  const scores = [
    { topic: 'Design', score: 72 },
    { topic: 'Speed', score: 88 },
    { topic: 'Support', score: 64 },
    { topic: 'Price', score: 79 },
    { topic: 'Docs', score: 91 },
  ];

  return (
    <RadarChart
      label="Satisfaction by topic"
      data={scores}
      dataKey="topic"
      series={[{ name: 'score', label: 'Satisfied', color: 'link' }]}
      unit="%"
      hasRadiusAxis
      radiusAxisProps={{ domain: [0, 100] }}
      showLabels
    />
  );
}

Colors​

A series' color takes a Bulma color name (primary, info, grey-dark and the rest), a shade of one of Bulma's six palette colors (primary-30, info-dark), or any CSS color. Bulma names draw with Bulma's own CSS variables, so they follow Theme and dark mode. A series with no color takes the next of Bulma's palette colors.

function example() {
  const seasons = [
    { stat: 'Goals', y2024: 12, y2025: 18 },
    { stat: 'Assists', y2024: 9, y2025: 11 },
    { stat: 'Tackles', y2024: 20, y2025: 16 },
    { stat: 'Saves', y2024: 6, y2025: 10 },
  ];

  return (
    <RadarChart
      label="Two seasons"
      data={seasons}
      dataKey="stat"
      series={[
        { name: 'y2024', label: '2024', color: 'primary-30' },
        { name: 'y2025', label: '2025', color: 'primary-60' },
      ]}
      hasLegend
      height={260}
    />
  );
}

Showing the Data Table​

The data table is always there for screen readers. showTable puts it on screen too, below the chart, and showLabel shows the chart's label above it as a caption.

function example() {
  const skills = [
    { skill: 'Speed', ana: 82, ben: 61 },
    { skill: 'Strength', ana: 54, ben: 88 },
    { skill: 'Stamina', ana: 76, ben: 72 },
  ];

  return (
    <RadarChart
      label="Player skills"
      showLabel
      showTable
      data={skills}
      dataKey="skill"
      angleAxisLabel="Skill"
      series={[
        { name: 'ana', label: 'Ana' },
        { name: 'ben', label: 'Ben' },
      ]}
      height={240}
    />
  );
}

Recharts Props and Children​

Each Recharts part the chart draws takes its own props after the chart's: radarProps for every Radar (here, thicker outlines), chartProps for Recharts' RadarChart (here, a smaller chart that starts from the right), angleAxisProps (here, the categories in capitals), and radiusAxisProps and tooltipProps. children adds more Recharts elements, or SVG of your own.

function example() {
  const skills = [
    { skill: 'Speed', ana: 82 },
    { skill: 'Strength', ana: 54 },
    { skill: 'Stamina', ana: 76 },
    { skill: 'Agility', ana: 90 },
  ];

  return (
    <RadarChart
      label="Player skills"
      data={skills}
      dataKey="skill"
      series={[{ name: 'ana', label: 'Ana', color: 'primary' }]}
      radarProps={{ strokeWidth: 3 }}
      chartProps={{ outerRadius: '65%', startAngle: 0, endAngle: 360 }}
      angleAxisProps={{ tickFormatter: (skill: string) => skill.toUpperCase() }}
    >
      <text
        x="50%"
        y={16}
        textAnchor="middle"
        fontSize={12}
        fill="var(--bulma-text-weak)"
      >
        Season average
      </text>
    </RadarChart>
  );
}

Size​

The chart fills its container's width and is 300 pixels tall. height changes that, and width and height take pixels or a percentage of the container. A chart sized in percent draws once the browser has measured its container, and its legend and data table render on the server either way.

<RadarChart
  label="Three skills"
  data={[
    { skill: 'Speed', ana: 82 },
    { skill: 'Strength', ana: 54 },
    { skill: 'Stamina', ana: 76 },
  ]}
  dataKey="skill"
  series={[{ name: 'ana', label: 'Ana' }]}
  width={320}
  height={220}
/>


Theming​

The chart draws its grid, axes and text from the same --bulma-chart-* variables as every chart in the package; BarChart's Theming section lists them. The ring around a point under the keyboard or the pointer takes --bulma-chart-stroke-color, which falls back to --bulma-scheme-main.


Accessibility​

  • The chart is a <figure> named by label, and its drawing is named by the same caption. description is read with the name of both. The data table takes the label as its caption.
  • A data table of every category and series renders beside the drawing, visually hidden with Bulma's is-sr-only, so a screen reader reads the values the shapes show (WAI: complex images). Its first column is a row header, headed by angleAxisLabel. showTable puts it on screen.
  • The drawing is a tab stop. Once it has focus, the left and right arrow keys move around the categories, and the tooltip shows each one's values, with a dot on each series' point.
  • Each legend entry is a button with aria-pressed. A hidden series' swatch is drawn hollow and its label greyed, so its state isn't told by color alone. A hidden series stays in the data table.
  • The swatches in the legend and tooltip are aria-hidden; each entry's text says which series it is.
  • Series colors are told apart by color alone in the drawing. When that matters, dash some series with strokeDasharray and say so in their labels, write the values with showLabels, or point readers to the data table.

  • BarChart: Values drawn as bars, one group per category.
  • ScatterChart: Points placed by two values, in groups.
  • Table: The Bulma table the chart's data table is drawn with.
  • LocaleProvider: The locale the chart writes its numbers in.
  • Helper Props: Bulma helper props for spacing, color, etc.

Additional Resources​


Props​

PropTypeDefaultDescription
datareadonly ChartRow[]—Required. The rows to draw: one per category around the chart, with a key per series.
dataKeystring—Required. The key of data that holds each row's category, such as skill, written around the chart.
seriesRadarChartSeries[]—Required. The series to draw, in order.
grid'polygon' | 'circle' | 'none''polygon'The grid's shape: rings with a corner at each category (polygon), round rings (circle), or none.
hasAngleAxisbooleantrueWrites the categories around the chart.
hasRadiusAxisbooleanfalseDraws the value scale, up from the center to the first category.
hasDotsbooleanfalseDraws a dot at each value.
fillOpacitynumber0.25How opaque each series' fill is, from 0 for an outline alone to 1. A series' own fillOpacity wins.
showLabelsbooleanfalseWrites each value on the chart beside its point.
angleAxisLabelstring—What the categories are, such as "Skill". It heads the data table's first column, which uses dataKey without one. The chart draws no title for it.
gridPropsPartial<PolarGridProps>—Props passed to Recharts' PolarGrid, after the chart's own.
angleAxisPropsPartial<PolarAngleAxisProps>—Props passed to Recharts' PolarAngleAxis, after the chart's own.
radiusAxisPropsPartial<PolarRadiusAxisProps>—Props passed to Recharts' PolarRadiusAxis, after the chart's own, such as domain.
radarPropsPartial<RadarProps>—Props passed to every Recharts Radar, after the chart's own.
chartPropsPartial<React.ComponentProps<typeof RechartsRadarChart>>—Props passed to Recharts' RadarChart, after the chart's own, such as outerRadius.
tooltipPropsPartial<TooltipProps>—Props passed to Recharts' Tooltip, after the chart's own.
classNamestring—Additional CSS classes to apply.
labelstring—Required. What the chart shows, such as "Monthly sales". It names the chart for assistive tech, and captions its data table. Shown above the chart with showLabel.
descriptionstring—A sentence or two on what the chart says, such as the trend it shows. A screen reader reads it with the chart's name. Not shown on screen.
showLabelbooleanfalseShows label above the chart as its caption.
showTablebooleanfalseShows the chart's data table below it. The table is always there for screen readers, which read the numbers from it; this puts it on screen as well.
hasTooltipbooleantrueShows a tooltip with the values under the pointer, or under the keyboard focus as the arrow keys move through the chart.
valueFormatterChartValueFormatter—Writes each value on the axes, in the tooltip, on the labels and in the data table. Without one, values are written as useNumberFormat writes a number, in the LocaleProvider's locale.
unitstring—Written after every value, such as % or kg.
widthChartSize'100%'The chart's width, in pixels or as a percentage of its container. A percentage makes the chart follow its container's size as the browser measures it. Recharts draws in the browser either way: a server render holds the figure, its caption, legend and data table, and the drawing appears once the page hydrates.
heightChartSize300The chart's height, in pixels or as a percentage of its container, which then needs a height of its own.
childrenReact.ReactNode—More Recharts elements to draw inside the chart, such as a Brush, a ReferenceArea, or <defs> for a pattern a color names with url(#id).
hasLegendbooleanfalseShows a legend. Each entry is a toggle button that hides or shows its series.
legendPosition'top' | 'bottom''bottom'Where the legend sits.
hiddenSeriesstring[]—The names of the series that are hidden, when you hold that state.
defaultHiddenSeriesstring[]—The names of the series hidden to begin with, when the chart holds it.
onHiddenSeriesChange(hiddenSeries: string[]) => void—Called with the names of the hidden series when the legend changes them.
refReact.Ref<HTMLElement>—Ref forwarded to the root <figure>.
...All standard HTML attributes and Bulma helper props—See Helper Props

Types:

  • ChartColor: Bulma color | `${(typeof paletteColors)[number]}-${(typeof validColorShades)[number]}` | (string & {}) — A color for a series, a slice or a mark. A Bulma color name such as primary or grey-light, a shade of one of Bulma's six palette colors such as primary-60 or info-dark, or any CSS color, such as #3e8ed0, var(--brand) or url(#stripes) for a pattern the chart's children define. A Bulma name draws with Bulma's own CSS variable, so it follows Theme and dark mode.
  • ChartRow: Record<string, any> — One row of a chart's data: an object whose keys the chart's dataKey and series name.
  • ChartSize: number | `${number}%` — A chart's width or height: pixels, or a percentage of its container.
  • ChartValueFormatter: (value: number) => string — Writes a value for the axes, the tooltip, the labels and the data table.
  • RadarChartSeries: One series of a radar chart: a shape drawn through its value at each category. Its fields:
    • fillOpacity: number — How opaque its fill is, from 0 to 1, in place of the chart's fillOpacity.
    • strokeDasharray: string — Dashes its outline, as an SVG stroke-dasharray such as '4 4'. Dashing some series tells them apart by more than color. The legend shows only the color, so say which series is dashed in its label or the chart's description.
    • name: string — Required. The key of data that holds this series' values, and the name hiddenSeries holds. No two series share one.
    • label: string — What the legend, the tooltip and the data table call it. Defaults to name.
    • color: ChartColor — Its color. Without one, it takes the next of Bulma's palette colors.