Swiftpack.co - ilamanov/SwiftPieChart as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ilamanov.
ilamanov/SwiftPieChart 1.0.61
Simple and elegant Pie Chart for SwiftUI
⭐️ 130
🕓 2 years ago
iOS macOS
.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: 130
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Fix more bugs
2 years ago

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