How to Install Nivo charts with npm in a React Project?

Terminal running npm install for @nivo/core and @nivo/bar beside Nivo package tiles

Nivo charts npm packages make adding visualisations to a React project straightforward. Rather than installing one large library, you add a small foundation package plus the chart types you actually need. This walkthrough covers prerequisites, installation commands, a first working chart and the most common setup problems developers meet along the way.

Prerequisites Before Installing

Nivo is a React library, so you need an existing React project created with a tool such as Vite, Next.js or another setup you already use. Node.js and a package manager like npm, Yarn or pnpm should be installed and working from your terminal.

Check that your React version is compatible with the Nivo release you plan to install. The peer dependency information listed for each package on npm, together with the repository release notes, shows which React versions are supported.

  • A working React project that starts without errors.
  • Node.js and a package manager available in the terminal.
  • A component file where the chart will live.
  • Sample data you want to visualise.

Choosing Which Packages to Install

Every chart type is published as a separate package under the @nivo scope. The installation instructions pair each chart package with @nivo/core, the shared foundation that provides theming and common utilities. Supporting packages such as axes, legends and tooltips are installed automatically as dependencies.

You want to buildPackages to installMain component
Bar chart@nivo/core @nivo/barResponsiveBar
Line or area chart@nivo/core @nivo/lineResponsiveLine
Pie or donut chart@nivo/core @nivo/pieResponsivePie
Calendar heatmap@nivo/core @nivo/calendarResponsiveCalendar
Treemap@nivo/core @nivo/treemapResponsiveTreeMap

Running the npm Install Command

Open a terminal in the project root, the folder containing package.json, and install the foundation together with your first chart package. The example below adds everything needed for a bar chart.

npm install @nivo/core @nivo/bar

Yarn and pnpm users can run the equivalent commands, yarn add @nivo/core @nivo/bar or pnpm add @nivo/core @nivo/bar. Adding more charts later only requires installing their packages, for example @nivo/line or @nivo/pie.

Keeping Package Versions Aligned

All @nivo packages are released together and are designed to work at matching versions. Mixing versions, such as an older @nivo/core with a newer chart package, can cause duplicated internals or type errors, so update all Nivo packages at the same time.

Creating Your First Chart Component

With the packages installed, create a component that imports the responsive chart, defines some data and renders the chart inside a container with a fixed height. The height matters because responsive charts size themselves from their parent element.

import { ResponsiveBar } from '@nivo/bar'

const data = [
  { country: 'UK', value: 120 },
  { country: 'US', value: 200 },
  { country: 'DE', value: 150 },
]

export default function SalesChart() {
  return (
    <div style={{ height: 360 }}>
      <ResponsiveBar
        data={data}
        keys={['value']}
        indexBy="country"
        margin={{ top: 20, right: 20, bottom: 50, left: 60 }}
        padding={0.3}
        colors={{ scheme: 'nivo' }}
        axisBottom={{ legend: 'Country', legendPosition: 'middle', legendOffset: 36 }}
      />
    </div>
  )
}

Import SalesChart into a page and start the development server. A three-bar chart with axes, hover tooltips and animated transitions should appear immediately.

Understanding the Key Props

Only a few props are required to get started, and the rest refine appearance and behaviour. Knowing what each one controls makes the documentation far easier to navigate when you begin customising.

  • data: the array of records the chart visualises.
  • keys: the value fields that become bars or stacked segments.
  • indexBy: the field used as the category label on the axis.
  • margin: space reserved around the plot for axes and legends.
  • colors: a colour scheme, array or function.
  • axisBottom and axisLeft: axis settings, or null to hide an axis.

Using Nivo with Next.js and Other Frameworks

Frameworks that render on the server need one extra consideration. Nivo charts depend on browser features such as measuring their container, so in the Next.js App Router the file containing the chart should be a client component marked with the use client directive.

Vite, Create React App style setups and other client-rendered projects need no additional configuration. Import the chart and render it like any other component.

Common Installation Problems and Fixes

Most issues after installation fall into a handful of predictable categories. Working through them in order usually resolves a blank or broken chart within minutes.

SymptomLikely causeFix
Chart area is emptyParent element has no heightGive the wrapper an explicit height
Module not found errorChart package missingInstall the specific @nivo package
Peer dependency warningsReact version mismatchCheck supported versions in release notes
Type errors after an updateMixed @nivo versionsUpdate all Nivo packages together
Error during server renderingChart rendered on the serverUse a client component

Where to Go After Installation

Once the first chart works, the nivo.rocks documentation becomes the most useful companion. Each chart page provides live controls that update a preview and generate matching code, which is an efficient way to discover props without reading every option.

Continue with the documentation walkthrough to learn how props and data formats are described, or browse practical examples for dashboard ideas.

Adding More Chart Types Later

Projects usually grow from one chart to several. Each new chart type only needs its own package, because @nivo/core is already installed. Running a single command such as npm install @nivo/line @nivo/pie adds line and pie charts without touching existing code.

Keep a short list of the Nivo packages your project uses in documentation or code comments. When upgrading, that list makes it easy to update every package together and confirm nothing was missed.

Removing Unused Packages

Charts sometimes get replaced during redesigns. Uninstalling packages you no longer import keeps the dependency tree tidy and avoids carrying unused code into future upgrades.

Verifying the Installation

A quick check confirms that everything installed correctly before you invest time in configuration. Listing the installed Nivo packages shows whether versions match and whether anything is missing.

npm ls @nivo/core @nivo/bar
  • Every @nivo package should report the same version.
  • No package should appear as missing or invalid.
  • The development server should start without module errors.
  • The sample chart should render with axes and tooltips.

Conclusion

Nivo charts npm installation comes down to adding @nivo/core plus the chart packages you need, importing a responsive component and rendering it inside a container with a defined height. Keeping package versions aligned and using client components in server-rendered frameworks prevents most problems.

With that foundation in place, every additional chart type is one install command away, and the same data-plus-props approach applies across the whole library.