Nivo Chart Customisation: Colours, Themes, Axes and Tooltips

Three Nivo bar charts showing greens, oranges and custom colour palettes for chart customisation

Nivo charts are designed to be shaped around your application rather than forcing a fixed look. Colours, typography, axes, legends, labels and tooltips can all be adjusted through props, and a shared theme keeps every chart consistent. This article walks through the main customisation areas and the props that control them.

Choosing and Mapping Colours

The colors prop is the starting point for most visual changes. It accepts a named scheme, an array of colour values, a function that returns a colour for each datum, or an object that reads colours from a field in your data. Named schemes come from d3-scale-chromatic, including categorical options such as nivo, category10, paired and set2.

Mapping colours from data is useful when categories must always use the same colour, for example brand-specific products. Store the colour on each record and point the colors prop at that field.

colors valueExampleUse case
Scheme object{ scheme: 'set2' }Quick, balanced palettes
Array['#22B39A', '#F7B731']Brand palettes
Functionbar => bar.data.colorColours stored in data

Borders and Inherited Colours

Props such as borderColor and labelTextColor accept inherit modifiers, for example darker or brighter versions of the element colour. This keeps borders and labels harmonious without defining every shade manually.

Building a Shared Theme

The theme prop controls everything that is not the data shapes themselves: fonts, axis lines and ticks, grid lines, legends, labels, annotations and tooltip containers. Defining one theme object and passing it to every chart creates a consistent visual language across dashboards.

const theme = {
  text: { fontFamily: 'Poppins, sans-serif', fontSize: 12, fill: '#4A5A70' },
  axis: { ticks: { line: { stroke: '#CBD5DC' } }, legend: { text: { fontWeight: 600 } } },
  grid: { line: { stroke: '#E2EAED', strokeDasharray: '4 4' } },
  legends: { text: { fontSize: 12 } },
  tooltip: { container: { borderRadius: 10, boxShadow: '0 8px 24px rgba(0,0,0,.1)' } },
}

Customising Axes and Grid Lines

Axes are configured through axisTop, axisRight, axisBottom and axisLeft. Each accepts settings for tick size, padding, rotation, legend text, legend position and offset, plus a format option for tick labels. Passing null hides an axis entirely.

Grid lines are toggled with enableGridX and enableGridY, and gridXValues or gridYValues can limit lines to specific values. Lighter grids usually improve readability, letting the data stand out.

  • Rotate long category labels with tickRotation.
  • Use format to add units, currency or percentages to ticks.
  • Reduce tick density with tickValues on narrow screens.
  • Increase margin when axis legends are cut off.

Legends and Labels

Legends are defined as an array in the legends prop, so a chart can show more than one. Each legend has an anchor, direction, item size, spacing and symbol shape, and hover effects can highlight the matching series.

Labels display values directly on shapes. Options such as enableLabel, labelSkipWidth and labelSkipHeight in bar charts hide labels on elements too small to fit them, preventing overlapping text.

Custom Tooltips and Interactions

The tooltip prop accepts a React component that receives the hovered element's data, giving complete control over content and layout. Custom tooltips are ideal for adding formatted values, comparisons or links to related views.

const Tip = ({ id, value, color }) => (
  <div style={{ padding: 10, background: '#fff', borderLeft: `4px solid ${color}` }}>
    <strong>{id}</strong>: {value.toLocaleString()}
  </div>
)

<ResponsiveBar data={data} keys={['value']} indexBy="country" tooltip={Tip} />

Event props such as onClick, onMouseEnter and onMouseLeave let charts drive the rest of an interface, for example filtering a table when a bar is clicked.

Patterns, Gradients and Custom Layers

Many charts support defs and fill props, which apply SVG patterns or gradients to selected elements. Patterns such as lines or dots are valuable for accessibility because they distinguish series without relying on colour alone.

The layers prop controls drawing order and accepts custom functions that render additional elements, such as target lines, annotations or centre labels in donut charts. Layers give advanced control while keeping the built-in behaviour intact.

Responsive Customisation

Responsive charts resize automatically, but good mobile layouts often need different props too. Reading the container width and adjusting margins, tick counts and legend placement keeps charts legible on narrow screens.

Moving legends below the chart, shortening labels and reducing label density are simple changes with a big impact on phones.

Adapting Margins to the Container

Margins reserve space for axes and legends, and fixed values that suit a desktop layout can waste room on a phone. Calculating margins from the container width keeps the plotting area as large as possible on every screen.

Customisation Checklist for Production Charts

Before shipping a chart, a short review ensures that customisation choices support readability rather than decoration. The checklist below covers the details that most often need attention.

AreaWhat to check
ColourConsistent meaning across charts and sufficient contrast
TypographyTheme font matches the application and sizes are legible
AxesUnits are clear and tick labels do not overlap
LegendsPlacement does not cover data on small screens
TooltipsValues are formatted and easy to scan
AccessibilityARIA labels and patterns support non-colour cues

Keeping Customisation Maintainable

Customisation grows over time, and scattered settings become hard to manage. Centralising themes, colour maps, axis formatters and tooltip components in a shared module keeps every chart aligned with a single source of truth.

Wrapping frequently used charts in your own components, for example a BrandBarChart with sensible defaults, means product teams only pass data and a few options. Updates to styling then happen in one place instead of across dozens of files.

  • Export one theme object and one colour map from a shared file.
  • Create formatter helpers for currency, percentages and dates.
  • Build wrapper components for repeated chart patterns.
  • Document defaults so new team members follow the same style.

Frequently Asked Questions

Can I use CSS to style Nivo charts?

Most styling is applied through props and the theme object rather than external CSS, which keeps SVG and Canvas renderers consistent.

How do I match my brand fonts?

Set fontFamily in the text section of the theme object, making sure the font is loaded by your application.

Can I disable animations for reports?

Yes. Set animate to false, or choose a calmer motionConfig preset when you want subtle transitions.

Conclusion

Nivo charts give you control over colours, themes, axes, legends, labels, tooltips, patterns and layers through clear, consistent props. A shared theme plus a small set of colour rules creates a professional, unified look across every visualisation.

Start with colours and theme, refine axes and labels, then add custom tooltips where they bring real value. The examples article shows these techniques working together in complete dashboards.