Skip to content

yasirfolio3/EasyBarChart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyBarChart

CI Status Version License Platform EasyBarChart hero EasyBarChart hero EasyBarChart hero EasyBarChart hero

Features

  1. This pod allows you to create multiple bar charts
  2. Ease of use has been the utmost priority as seen by the example.
  3. It supports both iPad and iPhone resolutions and in all orientations
  4. Please follow the example project for proper implementation especially for orientation changes.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Use this code to generate Charts:

@IBOutlet weak var collectionView: UICollectionView!
var items = [BarDataModel]()
var barDataSource: BarDataSource!

override func viewDidLoad() {
    super.viewDidLoad()

    self.populateTemporaryItems() 
    barDataSource = BarDataSource(items: items, collectionView: collectionView, cellHeightToWidthRatio: 5)
    collectionView.dataSource = barDataSource
    collectionView.reloadData()
}

//Method to fill items Array
func populateTemporaryItems() {
    for n in 0...20{
        let barModel = BarDataModel()
        barModel.showArrow = (n % 2 == 0)
        barModel.barSize = 50
        barModel.backgroundImage = UIImage(named: "paper")!
        barModel.separatorColor = UIColor.red
        barModel.categoryImage = UIImage(named: "png")!
        barModel.topLabelText = "50"
        barModel.topLabelTextColor = UIColor.white
        barModel.topLabelBackgroundColor = UIColor.red
        barModel.bottomLabelText = "Title"

        self.items.append(barModel)
    }
}

Use these methods in your viewcontroller to handle orientation and device changes:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    barDataSource.recalculateCellSizes()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    barDataSource.recalculateCellSizes()
}

Requirements

Swift 4.1
XCode 9.3

Installation

EasyBarChart is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'EasyBarChart'

Author

yasirfolio3, yali@folio3.com

License

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published