1.2.10 • Published 2 years ago

arc-pie-chart v1.2.10

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

Arc Pie Chart

downloads version dependencies typescript

pie chart that can be divided into several steps with Typescript

Install

npm install arc-pie-chart

Usage

It's just example

parageters

  • data : See the data format below.
  • totalDepth: your data's depth. (example is 3)
  • size: chart's px width
    • default is 500
    • you can change it by using css

declaration

import makePieChart from "arc-pie-chart";

const data = [...]

const chart = makePieChart(data, totalDepth, size); // svg tag <svg></svg>

React

import React, { useEffect, useRef } from "react";
import makePieChart from "arc-pie-chart";
import { data } from "./data";

function App() {
  const svg = useRef(null);
  const totalDepth = 3; // data's depth
  const size = 500; // px size

  useEffect(() => {
    if (svg.current) {
      svg.current.appendChild(makePieChart(data, totalDepth, size));
    }
  });

  return <div ref={svg} />;
}

export default App;

data format

  • You can create multi-level pie charts by connecting data arrays.
  • The sum of the percentages must be less than one hundred percent
const data = [
  {
    name: "INCOME",
    percentage: 55,
    color: "crimson",
    textColor: "black",
    data: [
      {
        name: "SALARY",
        percentage: 30,
        color: "crimson",
        textColor: "white",
      },
      {
        name: "BLOG",
        percentage: 30,
        color: "crimson",
        textColor: "white",
      },
      {
        name: "ETC",
        percentage: 40,
        color: "crimson",
        textColor: "white",
        data: [
          {
            name: "STOCK",
            percentage: 60,
            color: "crimson",
            textColor: "white",
          },
          {
            name: "GOLD",
            percentage: 40,
            color: "crimson",
            textColor: "white",
          },
        ],
      },
    ],
  },
  {
    name: "EXPENSE",
    percentage: 45,
    color: "#3BB6AE",
    textColor: "black",
    data: [
      {
        name: "EAT",
        percentage: 10,
        color: "#3BB6AE",
        textColor: "black",
      },
      {
        name: "LIFE",
        percentage: 20,
        color: "#3BB6AE",
        textColor: "black",
      },
      {
        name: "SHOPPING",
        percentage: 10,
        color: "#3BB6AE",
        textColor: "black",
      },
      {
        name: "BUS",
        percentage: 20,
        color: "#3BB6AE",
        textColor: "black",
        data: [
          {
            name: "FAST",
            percentage: 50,
            color: "#3BB6AE",
            textColor: "black",
          },
          {
            name: "SLOW",
            percentage: 50,
            color: "#3BB6AE",
            textColor: "black",
          },
        ],
      },
      {
        name: "HEALTH",
        percentage: 10,
        color: "#3BB6AE",
        textColor: "black",
      },
      {
        name: "CULTURE",
        percentage: 10,
        color: "#3BB6AE",
        textColor: "black",
      },
      {
        name: "ETC",
        percentage: 20,
        color: "#3BB6AE",
        textColor: "black",
      },
    ],
  },
];
1.2.10

2 years ago

1.2.0

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.9

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

4 years ago

1.1.0

4 years ago

1.1.3

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago