nivo
nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries
Top Related Projects
Redefined chart library built with React and D3
A collection of composable React components for building interactive data visualizations
📊 Interactive JavaScript Charts built on SVG
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Highcharts JS, the JavaScript charting framework
Quick Overview
Nivo is a powerful and flexible data visualization library for React. It provides a rich set of customizable chart components, including line charts, bar charts, pie charts, heatmaps, and more. Nivo is built on top of D3.js and React, offering a declarative approach to creating beautiful and interactive data visualizations.
Pros
- Wide variety of chart types and customization options
- Responsive and interactive charts out of the box
- Server-side rendering support
- Excellent documentation and examples
Cons
- Steep learning curve for advanced customizations
- Large bundle size due to dependencies
- Limited support for non-React environments
- Some chart types may have performance issues with large datasets
Code Examples
- Creating a simple bar chart:
import { ResponsiveBar } from '@nivo/bar'
const MyBarChart = ({ data }) => (
<ResponsiveBar
data={data}
keys={['hot dog', 'burger', 'sandwich', 'kebab', 'fries', 'donut']}
indexBy="country"
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
padding={0.3}
valueScale={{ type: 'linear' }}
indexScale={{ type: 'band', round: true }}
colors={{ scheme: 'nivo' }}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
}}
legends={[
{
dataFrom: 'keys',
anchor: 'bottom-right',
direction: 'column',
justify: false,
translateX: 120,
translateY: 0,
itemsSpacing: 2,
itemWidth: 100,
itemHeight: 20,
itemDirection: 'left-to-right',
itemOpacity: 0.85,
symbolSize: 20,
}
]}
/>
)
- Creating a line chart with multiple series:
import { ResponsiveLine } from '@nivo/line'
const MyLineChart = ({ data }) => (
<ResponsiveLine
data={data}
margin={{ top: 50, right: 110, bottom: 50, left: 60 }}
xScale={{ type: 'point' }}
yScale={{ type: 'linear', min: 'auto', max: 'auto', stacked: true, reverse: false }}
yFormat=" >-.2f"
axisTop={null}
axisRight={null}
axisBottom={{
orient: 'bottom',
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: 'transportation',
legendOffset: 36,
legendPosition: 'middle'
}}
axisLeft={{
orient: 'left',
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: 'count',
legendOffset: -40,
legendPosition: 'middle'
}}
pointSize={10}
pointColor={{ theme: 'background' }}
pointBorderWidth={2}
pointBorderColor={{ from: 'serieColor' }}
pointLabelYOffset={-12}
useMesh={true}
legends={[
{
anchor: 'bottom-right',
direction: 'column',
justify: false,
translateX: 100,
translateY: 0,
itemsSpacing: 0,
itemDirection: 'left-to-right',
itemWidth: 80,
itemHeight: 20,
itemOpacity: 0.75,
symbolSize: 12,
symbolShape: 'circle',
symbolBorderColor: 'rgba
Competitor Comparisons
Redefined chart library built with React and D3
Pros of Recharts
- Simpler API and easier learning curve for beginners
- Better performance with large datasets
- More customizable legend component
Cons of Recharts
- Less diverse chart types compared to Nivo
- Limited animation options
- Less flexibility in styling and customization
Code Comparison
Recharts:
<LineChart width={600} height={300} data={data}>
<XAxis dataKey="name" />
<YAxis />
<Line type="monotone" dataKey="value" stroke="#8884d8" />
</LineChart>
Nivo:
<ResponsiveLine
data={data}
margin={{ top: 50, right: 110, bottom: 50, left: 60 }}
xScale={{ type: 'point' }}
yScale={{ type: 'linear', min: 'auto', max: 'auto', stacked: true, reverse: false }}
axisBottom={{ orient: 'bottom', tickSize: 5, tickPadding: 5, tickRotation: 0 }}
/>
Both Recharts and Nivo are popular React charting libraries, each with its own strengths. Recharts offers a more straightforward approach, making it easier for beginners to create charts quickly. It also performs better with large datasets. On the other hand, Nivo provides a wider variety of chart types and more advanced customization options, albeit with a steeper learning curve. The code comparison shows that Recharts has a more concise syntax, while Nivo offers more detailed configuration options within its components.
A collection of composable React components for building interactive data visualizations
Pros of Victory
- More extensive documentation and examples
- Better support for custom animations and transitions
- Easier integration with React Native projects
Cons of Victory
- Steeper learning curve for beginners
- Less out-of-the-box chart types compared to Nivo
- Slightly larger bundle size
Code Comparison
Victory:
import { VictoryBar, VictoryChart, VictoryAxis } from 'victory';
<VictoryChart>
<VictoryAxis tickValues={[1, 2, 3, 4]} />
<VictoryAxis dependentAxis />
<VictoryBar data={data} x="quarter" y="earnings" />
</VictoryChart>
Nivo:
import { ResponsiveBar } from '@nivo/bar';
<ResponsiveBar
data={data}
keys={['earnings']}
indexBy="quarter"
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
padding={0.3}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
}}
/>
Both libraries offer powerful charting capabilities for React applications. Victory provides more flexibility for custom animations and React Native support, while Nivo offers a wider range of pre-built chart types and a simpler API for quick implementation. The choice between the two depends on specific project requirements and developer preferences.
📊 Interactive JavaScript Charts built on SVG
Pros of ApexCharts
- More extensive chart types and customization options
- Better performance with large datasets
- Easier to implement animations and interactivity
Cons of ApexCharts
- Larger bundle size
- Less focus on data visualization best practices
- Not as seamlessly integrated with React ecosystem
Code Comparison
Nivo (React):
import { ResponsiveLine } from '@nivo/line'
<ResponsiveLine
data={data}
margin={{ top: 50, right: 110, bottom: 50, left: 60 }}
xScale={{ type: 'point' }}
yScale={{ type: 'linear', min: 'auto', max: 'auto', stacked: true, reverse: false }}
/>
ApexCharts (React):
import Chart from 'react-apexcharts'
<Chart
options={{
chart: { type: 'line' },
xaxis: { categories: [1991, 1992, 1993, 1994, 1995] }
}}
series={[{ name: 'series-1', data: [30, 40, 45, 50, 49] }]}
type="line"
/>
Both libraries offer powerful charting capabilities, but they cater to different needs. Nivo focuses on React integration and adheres to data visualization best practices, while ApexCharts provides a wider range of chart types and customization options. The choice between them depends on specific project requirements and the developer's familiarity with each library's API.
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Lightweight and fast, with a smaller bundle size
- Extensive documentation and large community support
- Easier to set up and use for simple charts
Cons of Chart.js
- Less customizable and flexible compared to Nivo
- Limited animation options and interactivity features
- Fewer chart types available out of the box
Code Comparison
Chart.js example:
import Chart from 'chart.js/auto';
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow'],
datasets: [{
label: 'My Dataset',
data: [12, 19, 3]
}]
}
});
Nivo example:
import { ResponsiveBar } from '@nivo/bar'
<ResponsiveBar
data={[
{ color: 'Red', value: 12 },
{ color: 'Blue', value: 19 },
{ color: 'Yellow', value: 3 }
]}
keys={['value']}
indexBy="color"
/>
Both libraries offer easy-to-use APIs for creating charts, but Nivo's declarative approach using React components provides more flexibility and customization options. Chart.js is more straightforward for simple use cases, while Nivo excels in creating complex, interactive data visualizations with React integration.
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of D3
- Highly flexible and customizable, allowing for complex and unique visualizations
- Large ecosystem with extensive documentation and community support
- Directly manipulates the DOM, providing fine-grained control over rendering
Cons of D3
- Steeper learning curve, requiring more time to master
- More verbose code, often requiring more lines to achieve similar results
- Lower-level API, which can be overwhelming for simple visualizations
Code Comparison
D3:
const svg = d3.select("body").append("svg")
.attr("width", 400)
.attr("height", 300);
svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x", (d, i) => i * 45)
.attr("y", d => 300 - d * 10)
.attr("width", 40)
.attr("height", d => d * 10);
Nivo:
<ResponsiveBar
data={data}
keys={[ 'hot dog', 'burger', 'sandwich', 'kebab', 'fries', 'donut' ]}
indexBy="country"
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
padding={0.3}
colors={{ scheme: 'nivo' }}
/>
D3 offers more control but requires more code, while Nivo provides a higher-level abstraction for quicker implementation of common chart types.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- Extensive documentation and examples
- Wide range of chart types and customization options
- Strong browser compatibility, including older versions
Cons of Highcharts
- Commercial license required for most use cases
- Steeper learning curve due to its extensive feature set
- Larger file size, which may impact page load times
Code Comparison
Highcharts:
Highcharts.chart('container', {
chart: { type: 'bar' },
series: [{
data: [1, 2, 3, 4, 5]
}]
});
Nivo:
<ResponsiveBar
data={[
{ id: 'A', value: 1 },
{ id: 'B', value: 2 },
{ id: 'C', value: 3 },
{ id: 'D', value: 4 },
{ id: 'E', value: 5 }
]}
/>
Key Differences
- Highcharts uses a more traditional JavaScript approach, while Nivo is React-based
- Nivo offers a more modern, declarative API
- Highcharts provides more built-in interactivity out of the box
- Nivo is open-source and free for all use cases, unlike Highcharts
- Highcharts has a longer history and larger community, potentially offering more resources and support
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
nivo provides supercharged React components to easily build dataviz apps, it's built on top of d3.
Several libraries already exist for React d3 integration, but just a few provide server side rendering ability and fully declarative charts.
Installation
In order to use nivo, you have to install the @nivo/core
package and then choose
some of the scoped @nivo
packages according to the charts you wish to use:
yarn add @nivo/core @nivo/bar
Features
- Highly Customizable
- Motion/Transitions, powered by react-spring
- Interactive Components Playground
- Exhaustive Documentation
- SVG Charts
- HTML Charts
- Canvas Charts
- Server Side Rendering and HTTP API
- Patterns & Gradients
- Theming
- Responsive Charts
Discussion
Join the nivo discord community.
Packages & components
nivo is comprised of several packages/components, for a full list, please use the Components Explorer.
Guides
Backers
Donations are welcome to help improving nivo [Become a backer]
Open Collective Sponsors
Support this project by becoming a sponsor, your logo will show up here with a link to your website. [Become a sponsor]
Top Related Projects
Redefined chart library built with React and D3
A collection of composable React components for building interactive data visualizations
📊 Interactive JavaScript Charts built on SVG
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Highcharts JS, the JavaScript charting framework
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot