Socket
Socket
Sign inDemoInstall

@nivo/pie

Package Overview
Dependencies
Maintainers
2
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nivo/pie


Version published
Weekly downloads
215K
decreased by-2.85%
Maintainers
2
Weekly downloads
 
Created

What is @nivo/pie?

@nivo/pie is a React component from the Nivo library that allows you to create highly customizable and interactive pie charts. It provides a variety of features such as legends, tooltips, and animations, making it a powerful tool for data visualization.

What are @nivo/pie's main functionalities?

Basic Pie Chart

This code demonstrates how to create a basic pie chart using the @nivo/pie package. The chart is responsive and includes various customization options such as inner radius, pad angle, corner radius, and colors.

import { ResponsivePie } from '@nivo/pie';

const data = [
  { id: 'javascript', label: 'javascript', value: 29 },
  { id: 'python', label: 'python', value: 25 },
  { id: 'java', label: 'java', value: 20 },
  { id: 'ruby', label: 'ruby', value: 15 },
  { id: 'c++', label: 'c++', value: 11 }
];

const MyPieChart = () => (
  <ResponsivePie
    data={data}
    margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
    innerRadius={0.5}
    padAngle={0.7}
    cornerRadius={3}
    colors={{ scheme: 'nivo' }}
    borderWidth={1}
    borderColor={{ from: 'color', modifiers: [['darker', 0.2]] }}
    radialLabelsSkipAngle={10}
    radialLabelsTextXOffset={6}
    radialLabelsTextColor='#333333'
    radialLabelsLinkColor={{ from: 'color' }}
    sliceLabelsSkipAngle={10}
    sliceLabelsTextColor='#333333'
  />
);

Pie Chart with Legends

This code demonstrates how to add legends to a pie chart using the @nivo/pie package. The legends are positioned at the bottom of the chart and include hover effects for better interactivity.

import { ResponsivePie } from '@nivo/pie';

const data = [
  { id: 'javascript', label: 'javascript', value: 29 },
  { id: 'python', label: 'python', value: 25 },
  { id: 'java', label: 'java', value: 20 },
  { id: 'ruby', label: 'ruby', value: 15 },
  { id: 'c++', label: 'c++', value: 11 }
];

const MyPieChartWithLegends = () => (
  <ResponsivePie
    data={data}
    margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
    innerRadius={0.5}
    padAngle={0.7}
    cornerRadius={3}
    colors={{ scheme: 'nivo' }}
    borderWidth={1}
    borderColor={{ from: 'color', modifiers: [['darker', 0.2]] }}
    radialLabelsSkipAngle={10}
    radialLabelsTextXOffset={6}
    radialLabelsTextColor='#333333'
    radialLabelsLinkColor={{ from: 'color' }}
    sliceLabelsSkipAngle={10}
    sliceLabelsTextColor='#333333'
    legends={[
      {
        anchor: 'bottom',
        direction: 'row',
        justify: false,
        translateX: 0,
        translateY: 56,
        itemsSpacing: 0,
        itemWidth: 100,
        itemHeight: 18,
        itemTextColor: '#999',
        itemDirection: 'left-to-right',
        itemOpacity: 1,
        symbolSize: 18,
        symbolShape: 'circle',
        effects: [
          {
            on: 'hover',
            style: {
              itemTextColor: '#000'
            }
          }
        ]
      }
    ]}
  />
);

Pie Chart with Custom Tooltip

This code demonstrates how to create a pie chart with a custom tooltip using the @nivo/pie package. The custom tooltip displays the id and value of the hovered slice in a styled div.

import { ResponsivePie } from '@nivo/pie';

const data = [
  { id: 'javascript', label: 'javascript', value: 29 },
  { id: 'python', label: 'python', value: 25 },
  { id: 'java', label: 'java', value: 20 },
  { id: 'ruby', label: 'ruby', value: 15 },
  { id: 'c++', label: 'c++', value: 11 }
];

const CustomTooltip = ({ datum }) => (
  <div style={{ padding: 12, background: '#fff', border: '1px solid #ccc' }}>
    <strong>{datum.id}</strong>: {datum.value}
  </div>
);

const MyPieChartWithTooltip = () => (
  <ResponsivePie
    data={data}
    margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
    innerRadius={0.5}
    padAngle={0.7}
    cornerRadius={3}
    colors={{ scheme: 'nivo' }}
    borderWidth={1}
    borderColor={{ from: 'color', modifiers: [['darker', 0.2]] }}
    radialLabelsSkipAngle={10}
    radialLabelsTextXOffset={6}
    radialLabelsTextColor='#333333'
    radialLabelsLinkColor={{ from: 'color' }}
    sliceLabelsSkipAngle={10}
    sliceLabelsTextColor='#333333'
    tooltip={CustomTooltip}
  />
);

Other packages similar to @nivo/pie

Keywords

FAQs

Package last updated on 20 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc