Gathering detailed insights and metrics for react-minimal-pie-chart
Gathering detailed insights and metrics for react-minimal-pie-chart
Gathering detailed insights and metrics for react-minimal-pie-chart
Gathering detailed insights and metrics for react-minimal-pie-chart
react-native-pie-chart
pie chart for react native
cucumber-html-reporter
Generates Cucumber HTML reports in three different themes
react-native-gifted-charts
The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.
igniteui-react-charts
Ignite UI React charting components for building rich data visualizations using TypeScript APIs.
🍰 Lightweight but versatile SVG pie/donut charts for React. < 2kB gzipped.
npm install react-minimal-pie-chart
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
410 Stars
653 Commits
79 Forks
4 Watching
7 Branches
10 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
TypeScript (99.01%)
JavaScript (0.99%)
Cumulative downloads
Total Downloads
Last day
4%
15,437
Compared to previous day
Last week
-1.7%
75,713
Compared to previous week
Last month
3.8%
323,975
Compared to previous month
Last year
0.7%
4,088,021
Compared to previous year
37
Lightweight React SVG pie charts, with versatile options and CSS animation included. ~2kB gzipped. 👏 Demo 👏.
Because Recharts is awesome, but when you just need a simple pie/donought chart, 2kB are usually enough.
Size by Bundlefobia | Benchmark Size * | Loading time on a slow 3g * | |
---|---|---|---|
react-minimal-pie-chart (v9.0.0) | 1.99 KB | ~40 ms | |
rechart (v1.8.5) | 96.9 KB | ~1900 ms | |
victory-pie (v34.1.3) | 50.5 KB | ~1100 ms | |
react-apexcharts (v1.3.7) | 114.6 KB | ~2300 ms | |
react-vis (v1.11.7) | 78.3 KB | ~1600 ms |
* Benchmark carried out with size-limit with a "real-world" setup: see benchmark repo. (What matter here are not absolute values but the relation between magnitudes)
1npm install react-minimal-pie-chart
If you don't use a package manager, react-minimal-pie-chart
exposes also an UMD
module ready for the browser.
https://unpkg.com/react-minimal-pie-chart/dist/index.js
Minimum supported Typescript version: >= 3.8
1import { PieChart } from 'react-minimal-pie-chart'; 2 3<PieChart 4 data={[ 5 { title: 'One', value: 10, color: '#E38627' }, 6 { title: 'Two', value: 15, color: '#C13C37' }, 7 { title: 'Three', value: 20, color: '#6A2135' }, 8 ]} 9/>;
Property | Type | Description | Default |
---|---|---|---|
data | DataEntry[] | Source data. Each entry represents a chart segment | [] |
lineWidth | number (%) | Line width of each segment. Percentage of chart's radius | 100 |
startAngle | number | Start angle of first segment | 0 |
lengthAngle | number | Total angle taken by the chart (can be negative to make the chart clockwise!) | 360 |
totalValue | number | Total value represented by the full chart | - |
paddingAngle | number | Angle between two segments | - |
rounded | boolean | Round line caps of each segment | - |
segmentsShift | number or: (segmentIndex) => number | Translates segments radially. If number set, provide shift value relative to viewBoxSize space. If function , return a value for each segment.( radius prop might be adjusted to prevent segments from overflowing chart's boundaries) | - |
segmentsStyle | CSSObject or: (segmentIndex) => CSSObject | Style object assigned to each segment. If function , return a value for each segment. (Warning: SVG only supports its own CSS props). | - |
segmentsTabIndex | number | tabindex attribute assigned to segments | - |
label | (labelRenderProps) => string | number | ReactElement | A function returning a label value or the SVG element to be rendered as label | - |
labelPosition | number (%) | Label position from origin. Percentage of chart's radius (50 === middle point) | 50 |
labelStyle | CSSObject or: (segmentIndex) => CSSObject | Style object assigned to each label. If function set, return style for each label. (Warning: SVG only supports its own CSS props). | - |
animate | boolean | Animate segments on component mount | - |
animationDuration | number | Animation duration in ms | 500 |
animationEasing | string | A CSS easing function | ease-out |
reveal | number (%) | Turn on CSS animation and reveal just a percentage of each segment | - |
background | string | Segments' background color | - |
children | ReactElement (svg) | Elements rendered as children of SVG element (eg. SVG defs and gradient elements) | - |
radius | number (user units) | Radius of the pie (relative to viewBoxSize space) | 50 |
center | [number, number] | x and y coordinates of center (relative to viewBoxSize space) | [50, 50] |
viewBoxSize | [number, number] | width and height of SVG viewBox attribute | [100, 100] |
onBlur | (e, segmentIndex) => void | onBlur event handler for each segment | - |
onClick | (e, segmentIndex) => void | onClick event handler for each segment | - |
onFocus | (e, segmentIndex) => void | onFocus event handler for each segment | - |
onKeyDown | (e, segmentIndex) => void | onKeyDown event handler for each segment | - |
onMouseOut | (e, segmentIndex) => void | onMouseOut event handler for each segment | - |
onMouseOver | (e, segmentIndex) => void | onMouseOver event handler for each segment | - |
.oOo.oOo.oOo.oOo.oOo.oOo.oOo. |
Prop types are exposed for convenience:
1import type { PieChartProps } from 'react-minimal-pie-chart';
data
propdata
prop expects an array of chart entries as follows:
1type Data = { 2 color: string; 3 value: number; 4 key?: string | number; 5 title?: string | number; 6 [key: string]: any; 7}[];
Each entry accepts any custom property plus the following optional ones:
key
: custom value to be used as segments element keys
title
: title
element rendered as segment's child
label
render proplabel
prop accepts a function returning the string, number or element rendered as label for each segment:
1<PieChart 2 label={(labelRenderProps: LabelRenderProps) => 3 number | string | React.ReactElement | undefined | null 4 } 5/>
The function receives labelRenderProps
object as single argument:
1type LabelRenderProps = { 2 x: number; 3 y: number; 4 dx: number; 5 dy: number; 6 textAnchor: string; 7 dataEntry: { 8 ...props.data[dataIndex] 9 // props.data entry relative to the label extended with: 10 startAngle: number; 11 degrees: number; 12 percentage: number; 13 }; 14 dataIndex: number; 15 style: React.CSSProperties; 16};
Render entries' values as labels:
1label={({ dataEntry }) => dataEntry.value}
Render segment's percentage as labels:
1label={({ dataEntry }) => `${Math.round(dataEntry.percentage)} %`}
See examples in the demo source.
See demo and relative source here and here.
See demo and relative source.
Here is an updated browsers support list 🔍.
The main requirement of this library is an accurate rendering of SVG Stroke properties.
Please consider that Math.sign
and Object.assign
polyfills are required to support legacy browsers.
This library uses the stroke-dasharray
+ stroke-dashoffset
animation strategy described here.
transform
to mutate segments/labels positionssvg
element with any extra propThanks to you all (emoji key):
No vulnerabilities found.
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 1/7 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More