SwiftUICharts - A simple line and bar charting library that supports accessibility written using SwiftUI.

Related tags

Charts chart swiftui
Overview

SwiftUICharts

A simple line and bar charting library that support accessibility written using SwiftUI.

Usage

Vertical bar chart

let highIntensity = Legend(color: .orange, label: "High Intensity", order: 5)
let buildFitness = Legend(color: .yellow, label: "Build Fitness", order: 4)
let fatBurning = Legend(color: .green, label: "Fat Burning", order: 3)
let warmUp = Legend(color: .blue, label: "Warm Up", order: 2)
let low = Legend(color: .gray, label: "Low", order: 1)

let limit = DataPoint(value: 130, label: "5", legend: fatBurning)

let points: [DataPoint] = [
    .init(value: 70, label: "1", legend: low),
    .init(value: 90, label: "2", legend: warmUp),
    .init(value: 91, label: "3", legend: warmUp),
    .init(value: 92, label: "4", legend: warmUp),
    .init(value: 130, label: "5", legend: fatBurning),
    .init(value: 124, label: "6", legend: fatBurning),
    .init(value: 135, label: "7", legend: fatBurning),
    .init(value: 133, label: "8", legend: fatBurning),
    .init(value: 136, label: "9", legend: fatBurning),
    .init(value: 138, label: "10", legend: fatBurning),
    .init(value: 150, label: "11", legend: buildFitness),
    .init(value: 151, label: "12", legend: buildFitness),
    .init(value: 150, label: "13", legend: buildFitness),
    .init(value: 136, label: "14", legend: fatBurning),
    .init(value: 135, label: "15", legend: fatBurning),
    .init(value: 130, label: "16", legend: fatBurning),
    .init(value: 130, label: "17", legend: fatBurning),
    .init(value: 150, label: "18", legend: buildFitness),
    .init(value: 151, label: "19", legend: buildFitness),
    .init(value: 150, label: "20", legend: buildFitness),
    .init(value: 160, label: "21", legend: highIntensity),
    .init(value: 159, label: "22", legend: highIntensity),
    .init(value: 161, label: "23", legend: highIntensity),
    .init(value: 158, label: "24", legend: highIntensity),
] 

BarChartView(dataPoints: points, limit: limit)

Horizontal bar chart

let warmUp = Legend(color: .blue, label: "Warm Up", order: 2)
let low = Legend(color: .gray, label: "Low", order: 1)

let points: [DataPoint] = [
    .init(value: 70, label: "1", legend: low),
    .init(value: 90, label: "2", legend: warmUp),
    .init(value: 91, label: "3", legend: warmUp),
    .init(value: 92, label: "4", legend: warmUp)
] 

HorizontalBarChartView(dataPoints: points)

Line chart

let buildFitness = Legend(color: .yellow, label: "Build Fitness", order: 4)
let fatBurning = Legend(color: .green, label: "Fat Burning", order: 3)
let warmUp = Legend(color: .blue, label: "Warm Up", order: 2)
let low = Legend(color: .gray, label: "Low", order: 1)

let points: [DataPoint] = [
    .init(value: 70, label: "1", legend: low),
    .init(value: 90, label: "2", legend: warmUp),
    .init(value: 91, label: "3", legend: warmUp),
    .init(value: 92, label: "4", legend: warmUp),
    .init(value: 130, label: "5", legend: fatBurning),
    .init(value: 124, label: "6", legend: fatBurning),
    .init(value: 135, label: "7", legend: fatBurning),
    .init(value: 133, label: "8", legend: fatBurning),
    .init(value: 136, label: "9", legend: fatBurning),
    .init(value: 138, label: "10", legend: fatBurning),
    .init(value: 150, label: "11", legend: buildFitness),
    .init(value: 151, label: "12", legend: buildFitness),
    .init(value: 150, label: "13", legend: buildFitness)
]

LineChartView(dataPoints: points)

Installation

Add this Swift package in Xcode using its Github repository url. (File > Swift Packages > Add Package Dependency...)

Author

Majid Jabrayilov: [email protected]

License

SwiftUICharts is available under the MIT license. See the LICENSE file for more info.

Comments
  • Add DataPoint conform to Identifiable

    Add DataPoint conform to Identifiable

    Hello

    When you use DataPoint with same value and label you get alert like this

    ForEach<Array<DataPoint>, DataPoint, ModifiedContent<ModifiedContent<ModifiedContent<_ShapeView<Capsule, Color>, AccessibilityAttachmentModifier>, _OffsetEffect>, _FrameLayout>>: the ID DataPoint(startValue: 0.0, endValue: 6.0, label: SwiftUI.LocalizedStringKey(key: "%@", hasFormatting: true, arguments: [SwiftUI.LocalizedStringKey.FormatArgument(storage: SwiftUI.LocalizedStringKey.FormatArgument.Storage.value("kh", nil))]), legend: SwiftUICharts.Legend(color: blue, label: SwiftUI.LocalizedStringKey(key: "min", hasFormatting: false, arguments: []), order: 0), visible: true) 
    occurs multiple times within the collection, this will give undefined results!
    

    And app crash sometimes

    To resolve this issue I suggest to add conformance to the Identifiable protocol.

    I found this PR #3 with this same code suggestion and merged. But the code is no longer present now?

    opened by bourvill 3
  • Add options to style the bars views and fix label position

    Add options to style the bars views and fix label position

    I added two options to the BarChartStyle: - barsCornerRadius: CGFloat value that controls corner radius of the bars - barsCorners: UIRectCorner value that controls what corners should get a radius

    With this you can better customize the bars view. Just Capsule() wasn't that nice ;)

    And it fixes a bug, that the labels where not centered unter the bars

    opened by Urkman 3
  • Feature/add layout options

    Feature/add layout options

    Add some customisation options:

    • Change labelCount being optional. Default is dataPoints.count unless you specify a value.

    • Add axisColor property to be able to define the grid and axis data accordingly to specific design Default is .secondary unless you specify a custom colour value.

    • Add axisLeadingPadding property to provide some room if necessary. Default is 0 unless you specify a custom value.

    opened by MoveUpwardsDev 3
  • Feature/fix crash `Fatal error: each layout item may only occur once`

    Feature/fix crash `Fatal error: each layout item may only occur once`

    Library crash in case you add 2 chart views with the same DataPoints due to ForEach \.id being used.

    Same apply with Legend object if same colour is used in different Legends object.

    I reckon this is a specific use case but shall not make SwiftUI crash at run time.

    I fix the problem by adding DataPoint and Legend conformance to Identifiable protocol

    opened by MoveUpwardsDev 1
  • Detect when user touches individual Data Point in Bar Chart

    Detect when user touches individual Data Point in Bar Chart

    Motivation: Add ability to respond when user touches appropriate data point in Bar Chart.

    DataPoint.customId allows to map appropriate entity(data) in View.chartDataPointSelector upon user touch.

    opened by alex1704 0
  • Some improvements to HorizontalBarChartView

    Some improvements to HorizontalBarChartView

    Improvements (based on my own needs):

    • Supports custom text to show next to the bars (in my case I needed a different text than the default provided).
    • Adjusts the height and size of the bars and circles, respectively, when the size of the dynamic font changes.
    • Allows setting the max value for calculating the bar width (in my case I needed charts with different dataPoints to have a normalised width regardless of the max values of those dataPoints).

    I also changed RoundedRectangle by Capsule to guarantee the rounded edges no matter the height of the bar.

    Thanks for sharing SwiftUICharts!

    opened by boherna 0
Releases(0.7)
Owner
Majid Jabrayilov
Swift developer 👨🏻‍💻SwiftUI addicted 🚀Creator of @CardioBotApp for⌚️and📱Writing weekly posts about Swift development 📖
Majid Jabrayilov
SwiftChart - A simple line and area charting library for iOS.

SwiftChart A simple line and area charting library for iOS. ?? Line and area charts ?? Multiple series ?? Partially filled series ?? Works with signed

Giampaolo Bellavite 1k Jan 2, 2023
SwiftUICharts - A charts / plotting library for SwiftUI.

A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS and has accessibility features built in.

Will Dale 632 Jan 3, 2023
Elegant Line Graphs for iOS. (Charting library)

BEMSimpleLineGraph BEMSimpleLineGraph makes it easy to create and customize line graphs for iOS. BEMSimpleLineGraph is a charting library that makes i

Boris Emorine 2.7k Dec 26, 2022
SwiftUICharts - ChartView made in SwiftUI

SwiftUICharts Swift package for displaying charts effortlessly. V2 Beta 1 is released, if you would like to try it out you can find a demo project her

Andras Samu 4.7k Jan 1, 2023
A charting library to visualize and interact with a vector map on iOS. It's like Geochart but for iOS!

FSInteractiveMap A charting library to visualize data on a map. It's like geochart but for iOS! The idea behind this library is to load a SVG file of

Arthur 544 Dec 30, 2022
Declarative charting and visualization to use with SwiftUI

Chart Declarative charting and visualization to use with SwiftUI The package is in open development with a goal of making a declara

null 11 Jun 3, 2022
A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.

⚡ A powerful & easy to use chart library for Android ⚡ Charts is the iOS version of this library Table of Contents Quick Start Gradle Maven Documentat

Philipp Jahoda 36k Jan 5, 2023
Line Chart library for iOS written in Swift

Swift LineChart Usage var lineChart = LineChart() lineChart.addLine([3, 4, 9, 11, 13, 15]) Features Super simple Highly customizable Auto scaling Touc

Mirco Zeiss 601 Nov 15, 2022
Simple and intuitive iOS chart library. Contribution graph, clock chart, and bar chart.

TEAChart Simple and intuitive iOS chart library, for Pomotodo app. Contribution graph, clock chart, and bar chart. Supports Storyboard and is fully ac

柳东原 · Dongyuan Liu 1.2k Nov 29, 2022
Simple iOS Application built using UIKit displaying the list of Cryptocurrencies and a detailed screen with a line graph.

CryptoViewer Simple iOS Application built using UIKit displaying the list of Cryptocurrencies and a detailed screen with a line graph. Home Screen: Di

null 0 Jun 14, 2022
An interactive line chart written in SwiftUI with many customizations.

LineChartView LineChartView is a Swift Package written in SwiftUI to add a line chart to your app. It has many available customizations and is interac

Jonathan Gander 59 Dec 10, 2022
Demonstrate a way to build your own line chart without using any third-party library

LineChart This code demonstrate a way to build your own line chart without using any third-party library. It contains a simple yet effective algorithm

Van Hung Nguyen 0 Oct 17, 2021
Mac app for virtualizing Linux and macOS (supports M1/Apple Silicon)

Microverse is a thin virtualization app for macOS, which allows running Linux (and, soon, macOS) guest virtual machines, achieved with macOS' own virtualization framework.

Justin Spahr-Summers 121 Dec 21, 2022
FSLineChart A line chart library for iOS.

FSLineChart A line chart library for iOS. Screenshots Installing FSLineChart Add the contents of the FSLineChart project to your directory or simply a

Arthur 856 Nov 24, 2022
Repository with example app for using Bar chart

Gráfico de Barras (Exemplo) Repositório com app exemplo para o uso do gráfico de Barras. O gráfico de barras é um gráfico com barras retangulares e co

Felipe Leite 0 Nov 5, 2021
MSBBarChart is an easy to use bar chart library for iOS

MSBBarChart MSBBarChart is an easy to use bar chart library for iOS. Usage if you want to hide label above bar barChart.setOptions([.isHiddenLabelAbov

misyobun 45 May 3, 2022
Line plot like in Robinhood app in SwiftUI

RHLinePlot Line plot like in Robinhood app, in SwiftUI Looking for how to do the moving price label effect? Another repo here. P.S. Of course this is

Wirawit Rueopas 234 Dec 27, 2022
Fully customizable line chart for SwiftUI 🤩

?? CheesyChart Create amazing Crypto and Stock charts ?? ?? Looking for an easy to use and fully customizable charting solution written in SwiftUI? Th

adri567 13 Dec 14, 2022
SwiftUI Bar Chart

SwiftUI BarChart Lightweight and easy to use SwiftUI chart library for all Apple platforms Features Scaling on both axes Fully customizable axes (labe

Roman Baitaliuk 158 Jan 6, 2023