GithubHelp home page GithubHelp logo

romanbaitaliuk / barchart Goto Github PK

View Code? Open in Web Editor NEW
162.0 6.0 16.0 617 KB

SwiftUI Bar Chart

License: MIT License

Swift 100.00%
swiftui chart bar-chart swiftui-example swift-package swift-library ios watchos macos

barchart's Introduction

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

barchart's People

Contributors

romanbaitaliuk avatar vincentneo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

barchart's Issues

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

p-gum.Chart.test.mov

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.

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.

a59fee4#diff-0ce44077ebd2b44cc16c0050fe3f900972025a5a951e6fb0adc3771eee81da9e

Scrollable Chart

Hi,
I was wondering is there any update for the Scrollable feature?

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.

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.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.