New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nivo/line

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nivo/line

  • 0.88.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @nivo/line?

@nivo/line is a powerful and flexible library for creating line charts in React applications. It provides a wide range of customization options and is built on top of D3.js, making it suitable for creating complex and interactive data visualizations.

What are @nivo/line's main functionalities?

Basic Line Chart

This code demonstrates how to create a basic line chart using the @nivo/line package. The chart is responsive and includes various customization options for axes, colors, and points.

import { ResponsiveLine } from '@nivo/line';

const data = [
  {
    id: 'japan',
    color: 'hsl(348, 70%, 50%)',
    data: [
      { x: 'plane', y: 214 },
      { x: 'helicopter', y: 119 },
      { x: 'boat', y: 151 },
      { x: 'train', y: 91 },
      { x: 'subway', y: 190 },
      { x: 'bus', y: 211 },
      { x: 'car', y: 152 },
      { x: 'moto', y: 189 },
      { x: 'bicycle', y: 152 },
      { x: 'horse', y: 8 },
      { x: 'skateboard', y: 197 },
      { x: 'others', y: 107 }
    ]
  }
];

const MyResponsiveLine = () => (
  <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 }}
    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'
    }}
    colors={{ scheme: 'nivo' }}
    pointSize={10}
    pointColor={{ theme: 'background' }}
    pointBorderWidth={2}
    pointBorderColor={{ from: 'serieColor' }}
    pointLabelYOffset={-12}
    useMesh={true}
  />
);

Custom Line Styles

This code demonstrates how to customize the line styles in a line chart using the @nivo/line package. It includes options for line width, point size, and enabling slices for better interaction.

import { ResponsiveLine } from '@nivo/line';

const data = [
  {
    id: 'france',
    color: 'hsl(204, 70%, 50%)',
    data: [
      { x: 'plane', y: 123 },
      { x: 'helicopter', y: 98 },
      { x: 'boat', y: 150 },
      { x: 'train', y: 75 },
      { x: 'subway', y: 200 },
      { x: 'bus', y: 180 },
      { x: 'car', y: 130 },
      { x: 'moto', y: 170 },
      { x: 'bicycle', y: 140 },
      { x: 'horse', y: 10 },
      { x: 'skateboard', y: 190 },
      { x: 'others', y: 100 }
    ]
  }
];

const MyCustomLineStyles = () => (
  <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 }}
    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'
    }}
    colors={{ scheme: 'nivo' }}
    lineWidth={4}
    pointSize={12}
    pointColor={{ theme: 'background' }}
    pointBorderWidth={3}
    pointBorderColor={{ from: 'serieColor' }}
    pointLabelYOffset={-12}
    useMesh={true}
    enableSlices='x'
  />
);

Interactive Line Chart with Tooltips

This code demonstrates how to create an interactive line chart with tooltips using the @nivo/line package. The chart includes custom tooltips that display detailed information about each data point.

import { ResponsiveLine } from '@nivo/line';

const data = [
  {
    id: 'usa',
    color: 'hsl(100, 70%, 50%)',
    data: [
      { x: 'plane', y: 200 },
      { x: 'helicopter', y: 150 },
      { x: 'boat', y: 180 },
      { x: 'train', y: 120 },
      { x: 'subway', y: 220 },
      { x: 'bus', y: 170 },
      { x: 'car', y: 140 },
      { x: 'moto', y: 160 },
      { x: 'bicycle', y: 130 },
      { x: 'horse', y: 20 },
      { x: 'skateboard', y: 210 },
      { x: 'others', y: 110 }
    ]
  }
];

const MyInteractiveLineChart = () => (
  <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 }}
    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'
    }}
    colors={{ scheme: 'nivo' }}
    pointSize={10}
    pointColor={{ theme: 'background' }}
    pointBorderWidth={2}
    pointBorderColor={{ from: 'serieColor' }}
    pointLabelYOffset={-12}
    useMesh={true}
    enableSlices='x'
    tooltip={({ point }) => (
      <div
        style={{
          background: 'white',
          padding: '9px 12px',
          border: '1px solid #ccc'
        }}
      >
        <strong>{point.serieId}</strong>
        <br />
        {point.data.xFormatted}: {point.data.yFormatted}
      </div>
    )}
  />
);

Other packages similar to @nivo/line

Keywords

FAQs

Package last updated on 11 Nov 2024

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