DEV Community

Johnny Turco
Johnny Turco

Posted on

1

How to the Use React Minimal Pie Chart Library

react-minimal-pie-chart is a tiny, lightweight pie charting React library. After reviewing the landscape, react-minimal-pie-chart is the smallest and simplest way to create pie (or donut) charts for your React app. The following is a quick introduction to get you up and running.

First, install the library:



npm install react-minimal-pie-chart


Enter fullscreen mode Exit fullscreen mode

And import it into your component:



import { PieChart } from 'react-minimal-pie-chart';


Enter fullscreen mode Exit fullscreen mode

Now you can use the <PieChart /> component.

There are quite a few options you can use to customize your pie charts. The most basic and important property is the data property, which takes an array of objects. A basic chart will have the following keys: title, value, and color. For example, your data attribute might look like this:



data={[
    {
      title: "Test 1",
      value: 50,
      color: "#000000"
    },
    {
      title: "Test 2",
      value: 50,
      color: "#ffffff"
    }
]}


Enter fullscreen mode Exit fullscreen mode

To get your labels to show up, you'll need to add the following property: label={({ dataEntry }) => dataEntry.title}.

And to style your labels, you set the labelStyle property to an object of SVG CSS properties and values. For example:



labelStyle={{
    fill: "white",
    fontSize: "5px",
    fontFamily: "Helvetica Neue,sans-serif",
    textShadow: "1px 1px 5px #000"
    }}


Enter fullscreen mode Exit fullscreen mode

You can also position your labels with labelPosition, which takes a number 0-100 (for a percent from center).

Here is a complete example of a basic pie chart component:



<PieChart
    label={({ dataEntry }) => dataEntry.title}
    labelStyle={
        {
            fill: "white",
            fontSize: "5px",
            fontFamily: "Helvetica Neue,sans-serif",
            textShadow: "1px 1px 5px #000"
        }
    }
    labelPosition={75}
    data={
        [
            {
              title: "Test 1",
              value: 50,
              color: "#000000"
            },
            {
              title: "Test 2",
              value: 50,
              color: "#ffffff"
            }
        ]
    }
/>


Enter fullscreen mode Exit fullscreen mode

Which will give you a pie chart that looks like this:
Image of pie chart example

If you want to add more, you can animate your pie chart on component render and even add mouse interactions. Check out the documentation here.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post →

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️