simple-pie creates simple svg pie and doughnut charts for infographics like graphs and others in browser environments.
simple-pie
npm install simple-pie --save
pnpm add simple-pie
yarn add simple-pie
import {simplePie, simpleDoughnut} from "simple-pie"; const svgPie = simplePie([2, 1, 1, 2]);const svgDoughnut = simpleDoughnut([2, 1, 1, 2]); document.body.appendChild(svgPie);document.body.appendChild(svgDoughnut);
// Pietype TPieOptions = { pallet?: string[]; borderColor?: string; borderWidth?: number;}; function simplePie( values: number[], options?: TPieOptions): SVGElement; // Doughnuttype TDoughnutOptions = TPieOptions & { inner?: number; // 0..1 - percent from outer radius}; function simpleDoughnut( values: number[], options: TDoughnutOptions = {}): SVGElement
simplePie([2, 1, 1, 2])
simplePie([2, 1, 1, 2], { borderColor: "transparent"})
simpleDoughnut([2, 1, 1, 2], { borderWidth: 3})
simpleDoughnut([2, 1, 1, 2], { borderColor: "transparent", inner: 0.3,})
<div id="pie-container"></div><div id="doughnut-container"></div> <script src="simple-pie.min.js"></script><script> const svgPieElement = simplePie([2, 1, 1, 2]); document.getElementById('pie-container').appendChild(svgPieElement); const svgDoughnutElement = simpleDoughnut([2, 1, 1, 2]); document.getElementById('doughnut-container').appendChild(svgDoughnutElement);</script>
import {simplePie} from "simple-pie"; const element = simplePie([2, 1, 1, 2]);element.setAttribute("width", "70");element.setAttribute("height", "70"); const svg = new XMLSerializer().serializeToString(element);const dataUri = `data:image/svg+xml;base64,${btoa(svg)}`; // Example for vis-network diagramconst nodes = new DataSet([{ id: 1, shape: "image", image: dataUri, shapeProperties: { useImageSize: true },},...