GithubHelp home page GithubHelp logo

stackviewbarchart's Introduction

StackViewBarChart

Carthage compatible Twitter

Create a simple bar chart with UIStackView, because...why not?

UIStackView is my favorite AutoLayout tool now, so part of the project's goal is to explore UIStackView's capability. It turns out it is fairly easy to create a bar chart with UIStackView.

Features

  • Customize chart legends
  • Implemented completely with UIStackView
  • Gradual bar color
  • Tiny code base (only 2 view classes)
  • Easy to folk and modify to use in your project

Screenshots

Requirements

  • iOS >= 12.0
  • Swift >= 5.0

Usage

Adding the StackViewBarChart to your project:

There are two ways to add the ScrollableGraphView to your project.

Manually

Add all of the files in the Classes directory to your project in Xcode to your project in Xcode.

Carthage

Add to your Cartfile:

github "haojianzong/StackViewBarChart" ~> 0.5.3

Then make sure to link the frameworks and import StackViewBarChart in your code.

CocoaPods

CocoaPods is not supported

Creating a bar chart with data.

Create a StackViewBarChart instance then set its numberList property with custom data.

```swift
class ViewController: UIViewController {

    // Initialize an instance
    let barChart = StackViewBarChart(frame: .zero)

    override func viewDidLoad() {
        super.viewDidLoad()

        // Setup its frame
        view.addSubview(barChart)
        barChart.frame = CGRect
        barChart.frame = CGRect(x: 0, y: 0, width: 300, height: 300)

        // Set the data
        barChart.dataList = [
          .init(legend: "M", number: 0),
          .init(legend: "T", number: 2),
          .init(legend: "W", number: 7),
          .init(legend: "T", number: 8),
          .init(legend: "F", number: 30),
          .init(legend: "S", number: 20),
          .init(legend: "S", number: 10)
    }
}
```  

Known Issues

  • Only support positive numbers
  • Autolayout warnings when there are too many bars and the frame is too small

Other

Follow me on twitter for interesting updates about other things that I make.

stackviewbarchart's People

Contributors

haojianzong avatar

Stargazers

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

Watchers

 avatar  avatar

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.