SwiftUI Bar Chart

Overview

SwiftUI BarChart

Lightweight and easy to use SwiftUI chart library for all Apple platforms

Features

  • Scaling on both axes
  • Fully customizable axes (labels font, color, dashed lines)
  • Custom gradient bars
  • Reactive chart configuration
  • Bar selection API
  • [WIP] horizontal scrolling

Requirements

  • iOS 13+ / macOS 10.15+ / watchOS 6+ / tvOS 13+
  • Xcode 11.0+
  • Swift 5+

Installation

Swift Package Manager

Add this swift package to your project

https://github.com/dawigr/BarChart.git

Usage

See Wiki for usage details

Help

If you like the library, you could:

  • Contribute code, issues and pull requests
  • Let other people know about it
  • paypal any amount to accelaerate new feature development

License

BarChart is released under the MIT license. See LICENSE for details

Comments
  • Chart Config ignore on Appear and Disapear

    Chart Config ignore on Appear and Disapear

    I have implement that chart, however, when I switch to another tabview and return back, the config setting get ignores or sometimes doesn't show the data at all. Here is my code:

    `var body:some View { let drag = DragGesture() .onChanged({ self.offset = $0.translation }) .onEnded({ if $0.translation.width < -50 { self.offset = .init(width:-1000, height: 0) dragDirection = .left } else if $0.translation.width > 50 { self.offset = .init(width: 1000, height: 0) dragDirection = .right } else { self.offset = .zero } }) ZStack {

            Text("No Data Available...").opacity(self.entries.isEmpty ? 1.0:0.0)
            VStack(alignment: .leading, spacing: 0) {
                
                self.selectionIndicatorView()
                
                SelectableBarChartView<SelectionLine>(config: self.config)
                .onBarSelection { entry, location in
                    self.selectedBarTopCentreLocation = location
                    self.selectedEntry = entry
                }
                .selectionView {
                    SelectionLine(location: self.selectedBarTopCentreLocation,
                                  height: 150)
                }
                .onAppear() {
    
                    
                    HealthKitData.instance.configDataEntities(index, dragDirection, endDate: endDate, dataType: .chartData, requestedData: requestedData, completionChartData: { (data,total,begin,end,endDate) in
                        self.entries = data
                        self.config.data.entries = data
                        configChartSettings()
                        self.totalSteps = total
                        self.beginTime = begin
                        self.endTime = end
                        self.endDate = endDate
                        
                    }, completionComponentData: {_ in })
                    
                }
                    .animation(.easeInOut)
                .onDisappear() {
                    tempIndex = .Day
                    index = .Day
                    endDate = Date()
                    dragDirection = .nothing
                    self.hasAppeared = true
                }
                
                  
                    .onReceive([index].publisher.last(), perform: { value in
                        
                        if value != tempIndex {
                            
                            if randomData {
                                self.entries = randomEntries()
                            } else {
                                switch index {
                                case .Day:
                                    self.config.xAxis.ticksInterval = 4
                                case .Week:
                                    self.config.xAxis.ticksInterval = 1
                                case .Month:
                                    self.config.xAxis.ticksInterval = 7
                                case .Year:
                                    self.config.xAxis.ticksInterval = 1
                                }
                                tempIndex = index
                                endDate = Date()
                               
                                HealthKitData.instance.configDataEntities(index, dragDirection, endDate: endDate, dataType: .chartData, requestedData: requestedData, completionChartData: { (data,total,begin,end,endDate) in
                                    self.entries = data
                                    self.config.data.entries = data
                                    configChartSettings()
                                    self.totalSteps = total
                                    self.beginTime = begin
                                    self.endTime = end
                                    //self.dragDirection = .nothing
                                    self.endDate = endDate
                                    tempIndex = index
                                }, completionComponentData: {_ in })
                                
                            }
                            self.selectedEntry = nil
                            self.selectedBarTopCentreLocation = nil
                        }
                    })
                    .onReceive([dragDirection].publisher.first(), perform: { value in
                        if value != .nothing && dragDirection != .nothing {
                            
                            HealthKitData.instance.configDataEntities(index, dragDirection, endDate: endDate, dataType: .chartData, requestedData: requestedData, completionChartData: { (data,total,begin,end,endDate) in
                                self.entries = data
                                self.config.data.entries = data
                                configChartSettings()
                                self.totalSteps = total
                                self.beginTime = begin
                                self.endTime = end
                                self.dragDirection = .nothing
                                self.endDate = endDate
                            }, completionComponentData: {_ in })
    
                        }
                    })
            }.padding(15)
        }
        .gesture(drag)
    
    }
    
    func configChartSettings() {
        let labelsFont = CTFontCreateWithName(("SFProText-Regular" as CFString), 10, nil)
        tempIndex = index
        
        self.config.labelsCTFont = labelsFont
        self.config.data.gradientColor = GradientColor(start: Color("GraphGradientStart"), end: Color("GraphGradientEnd"))
        
        self.config.xAxis.ticksDash = [2, 4]
        self.config.xAxis.labelsColor = .gray
        self.config.xAxis.ticksColor = .clear //.gray
        
        
        
        
        self.config.yAxis.labelsColor = .gray
        self.config.yAxis.ticksColor = .gray
        self.config.yAxis.ticksDash = [2, 2]
        self.config.yAxis.minTicksSpacing = 20.0
        self.config.yAxis.formatter = { (value, decimals) in
            let format = value == 0 ? "" : ""
            return String(format: " %.\(decimals)f\(format)", value)
        }
    }`
    

    and here is an screen of the app

    https://user-images.githubusercontent.com/16289125/115393740-41ed5900-a1f7-11eb-93f3-65e4edf51e60.mov

    opened by gharary 3
  • Negative values are not shown in Xcode 12 and through error

    Negative values are not shown in Xcode 12 and through error " Invalid frame dimension (negative or non-finite)"

    I have run this project in Xcode 12 and It through below error in Swift UI.

    SelectableBarChartExample-iOS[31888:477881] [SwiftUI] Invalid frame dimension (negative or non-finite).

    Screenshot 2021-01-08 at 7 09 29 PM

    opened by shipra-ios 1
  • This project should follow semantic versioning standards for SPM releases

    This project should follow semantic versioning standards for SPM releases

    Release 1.3.2 had a breaking interface change which causes problems for teams that use SPM 'next major' versioning. This API change was also not denoted in the release notes. Not a huge deal, my team was able to update our code. That having been said, SPM works really well when Semantic Versioning is followed as recommended by Apple.

    Very handy library, I hope to see new releases take this into consideration.

    The property dash on AxisBase.swift was refactored/reworked to style.

    https://github.com/romanbaitaliuk/BarChart/commit/a59fee439e156c02a5610771817881c61a96d06b#diff-0ce44077ebd2b44cc16c0050fe3f900972025a5a951e6fb0adc3771eee81da9e

    opened by SwiftNativeDeveloper 0
  • xAxis Label

    xAxis Label

    Hi, I am working on a project that utilizes your amazing Barchart system. I encountered a situation I am hoping the community can assist me on.

    I have a a list of two Months, February to March.
    For Data we have 31 days.
    I have values on February 14, and March 14. If I have just the days stored. 1-13, There's no way to know if it's March 14 or February 14. The Indices for XAxis Listed are "14, 21, 28, 7, 14". As you can see, you can not tell what month it us. When I select, March 14, The system only see's 14, and will pick Feb 14, not March 14. I changed the Indice tobe: "Feb 14, Feb 21, Feb 28, Mar 7, Mar 14" For the labels under chart. Unformately my team wants just number. While this works but the team want the labels to behave as before.

    Does anyone have ideas of what I can do in this framework? I looked for properties I can access but nothing public can be used without causing other unwanted behavior. I am hoping someone more familiar with the framework can offer suggestions. Thank you in advance for those are able to help.

    opened by LengTrang 0
  • Any ETA on

    Any ETA on "[WIP] horizontal scrolling" ?

    Hey Guys, love your work. Do you happen to have an ETA on that feature? "[WIP] horizontal scrolling" Thats the only feature missing for it to be an amazing lib :)

    Thanks in advance

    opened by AnatoliBenke-Helsana 0
  • Publishing changes from background threads is not allowed;

    Publishing changes from background threads is not allowed;

    I'm using your library however it gives an error in ChartConfiguration.swift file.

    Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.

    opened by gharary 0
  • Set a max label value on the Y-axis

    Set a max label value on the Y-axis

    Hi,

    first of all thanks for the great library.

    Would it be possibly to set a max label value on the YAxis?

    What I am trying to achieve is the following:

    The highest possible value that can be displayed in my chart is 17. Therefore I would only like to show YAxis-label and lines until 15. At the moment, however the chart automatically draws a label / line at 20.

    opened by jurahero 0
Releases(1.3.2)
Owner
Roman Baitaliuk
Roman Baitaliuk
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
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
Draw a chart with progress bar style

ChartProgressBar-iOS Draw a chart with progress bar style - the android version here Installation iOS version (9.0,*) Swift 3.2 Using cocoapods : pod

Hadi Dbouk 84 Apr 25, 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
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
A SwiftUI Framework for Drawing Chart

PrettyAxis A SwiftUI Framework for drawing charts. Fearture Support Drawing Bar Chart RadarChart Line Chart and Scatter Charts Pie Chart and Donut Cha

RiuHDuo 24 Oct 2, 2022
Demo-implementation of 5 different Chart Libraries in SwiftUI

Comparison of Chart Libraries for SwiftUI Read the entire blog post including images on jannikarndt.de! I want to add charts to my SwiftUI iOS App, Ze

Jannik Arndt 73 Oct 12, 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
A SwiftUI Contribution Chart (GitHub-like) implementation package

ContributionChart A contribution chart (aka. heatmap, GitHub-like) library for iOS, macOS, and watchOS. 100% written in SwiftUI. It Supports Custom Bl

null 41 Dec 27, 2022
A simple and beautiful chart lib used in Piner and CoinsMan for iOS(https://github.com/kevinzhow/PNChart) Swift Implementation

PNChart-Swift PNChart(https://github.com/kevinzhow/PNChart) Swift Implementation Installation This isn't on CocoaPods yet, so to install, add this to

Kevin 1.4k Nov 7, 2022
TKRadarChart - A customizable radar chart in Swift

TKRadarChart A customizable radar chart in Swift Requirements iOS 8.0+ Xcode 9.0 Swift 4.0 Installation CocoaPods You can use CocoaPods to install TKR

TBXark 203 Dec 28, 2022
A simple and beautiful chart lib used in Piner and CoinsMan for iOS

PNChart You can also find swift version at here https://github.com/kevinzhow/PNChart-Swift A simple and beautiful chart lib with animation used in Pin

Kevin 9.8k Jan 6, 2023
iOS Chart. Support animation, click, scroll, area highlight.

XJYChart XJYChart - A High-performance, Elegant, Easy-to-integrate Charting Framework. The Best iOS Objc Charts. chart more beautiful support chart sc

junyixie 868 Nov 16, 2022
A simple and animated Pie Chart for your iOS app.

XYPieChart XYPieChart is an simple and easy-to-use pie chart for iOS app. It started from a Potion Project which needs an animated pie graph without i

XY Feng 1.7k Sep 6, 2022
iOS/iPhone/iPad Chart, Graph. Event handling and animation supported.

#EChart A highly extendable, easy to use chart with event handling, animation supported. ##Test How To Use Download and run the EChartDemo project is

Scott Zhu 646 Dec 27, 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
ANDLineChartView is easy to use view-based class for displaying animated line chart.

ANDLineChartView for iOS ANDLineChartView is easy to use view-based class for displaying animated line chart. Usage API is simple. Just implement foll

Andrzej Naglik 421 Dec 11, 2022
Flower-like chart written in Swift

FlowerChart - custom chart written in Swift Fully vector flower-shaped chart written in Swift Flower-shaped chart written in Swift, this repo is a sam

Alexander Telegin 15 Jun 9, 2021