Swiftpack.co -  ilamanov/SwiftPieChart as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
ilamanov/SwiftPieChart
Simple and elegant Pie Chart for SwiftUI
.package(url: "https://github.com/ilamanov/SwiftPieChart.git", from: "1.0.61")

SwiftPieChart

Simple and elegant pie chart for Swift UI

SwiftUI Pie Chart

Usage

import SwiftPieChart

...

PieChartView(
    values: [1300, 500, 300],
    names: ["Rent", "Transport", "Education"],
    formatter: {value in String(format: "$%.2f", value)})

formatter is used to format the values for displaying purposes. In the example above we are displaying values with 2 decimal places and with the $ sign in the front.

Installation

In Xcode go to File -> Swift Packages -> Add Package Dependency and paste in the repo's url: https://github.com/ilamanov/SwiftPieChart

Demo

A demo iOS app shown in the gif above can be found at https://github.com/ilamanov/SwiftPieChartDemo

Code explanation

Easy Customization

You can change the width of the pie chart by providing widthFraction parameter:

PieChartView(
    values: [1300, 500, 300],
    names: ["Rent", "Transport", "Education"],
    formatter: {value in String(format: "$%.2f", value)},
    widthFraction: 0.95)

SwiftUI Pie Chart Wider

You can change the radius of the inner circle by providing innerRadiusFraction parameter:

PieChartView(
    values: [1300, 500, 300],
    names: ["Rent", "Transport", "Education"],
    formatter: {value in String(format: "$%.2f", value)},
    innerRadiusFraction: 0.5)

SwiftUI Pie Chart Wider Radius

You can change the colors by providing colors and backgroundColor parameters:

PieChartView(
    values: [1300, 500, 300],
    names: ["Rent", "Transport", "Education"],
    formatter: {value in String(format: "$%.2f", value)},
    colors: [Color.red, Color.purple, Color.orange],
    backgroundColor: Color(red: 30 / 255, green: 54 / 255, blue: 14 / 255, opacity: 1.0))

SwiftUI Pie Chart Alternate Colors

GitHub

link
Stars: 1
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Fix more bugs
1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API