A simple Line Chart Lib
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.bundle
.github
ChartPlayground.playground
MLLineChart.xcodeproj
MLLineChart.xcworkspace
Sources
Tests
docs
scripts
.gitignore
.jazzy.yml
.ruby-version
.swift-version
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Cartfile
Cartfile.private
Cartfile.resolved
Dangerfile
Gemfile
LICENSE
MLLineChart.podspec
Package.resolved
Package.swift
Readme.md

Readme.md

MLLineChart

 

Swift 4.2 Platforms License Swift Package Manager Carthage compatible CocoaPods compatible Travis

A Simple Line Chart Library

Requirements

  • iOS 10.0+ / tvOS 9.0+
  • Xcode 9.0+

Installation

CocoaPods

Add the following line to your Podfile:

pod "MLLineChart"

$ pod install

Dependency Managers

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate MLLineChart into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

pod 'MLLineChart', '~> 1.2.0'

Then, run the following command:

$ pod install
Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate MLLineChart into your Xcode project using Carthage, specify it in your Cartfile:

github "micheltlutz/MLLineChart" ~> 1.2.0
Swift Package Manager

To use MLLineChart as a Swift Package Manager package just add the following in your Package.swift file.

// swift-tools-version:4.2

import PackageDescription

let package = Package(
    name: "HelloMLLineChart",
    dependencies: [
        .package(url: "https://github.com/micheltlutz/MLLineChart.git", .upToNextMajor(from: "1.2.0"))
    ],
    targets: [
        .target(name: "HelloMLLineChart", dependencies: ["MLLineChart"])
    ]
)

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate MLLineChart into your project manually.

Git Submodules

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
$ git init
  • Add MLLineChart as a git submodule by running the following command:
$ git submodule add https://github.com/micheltlutz/MLLineChart.git
$ git submodule update --init --recursive
  • Open the new MLLineChart folder, and drag the MLLineChart.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the MLLineChart.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • You will see two different MLLineChart.xcodeproj folders each with two different versions of the MLLineChart.framework nested inside a Products folder.

    It does not matter which Products folder you choose from.

  • Select the MLLineChart.framework.

  • And that's it!

The MLLineChart.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

Embedded Binaries

  • Download the latest release from https://github.com/micheltlutz/MLLineChart/releases
  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "General" panel.
  • Click on the + button under the "Embedded Binaries" section.
  • Add the downloaded MLLineChart.framework.
  • And that's it!

Usage

import MLLineChart

class ViewController: UIViewController {
    private var lineLinearChart: MLLineChart!
    private var dataEntries: [MLPointEntry] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        makeData()
        setupChart()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        lineLinearChart.animate()
    }

    private func makeData() {
        dataEntries.append(MLPointEntry(value: 0, label: "1", color: UIColor.init(hex: "f0f0f0"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 6, label: "2", color: UIColor.init(hex: "70A886"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 6, label: "3", color: UIColor.init(hex: "70A886"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 5, label: "4", color: UIColor.init(hex: "F3A634"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 5, label: "5", color: UIColor.init(hex: "F3A634"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 3, label: "6", color: UIColor.init(hex: "EB7F33"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 5, label: "7", color: UIColor.init(hex: "F3A634"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 4, label: "8", color: UIColor.init(hex: "F29D53"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 5, label: "9", color: UIColor.init(hex: "F3A634"), bubbleConfig: nil))
        dataEntries.append(MLPointEntry(value: 3, label: "10", color: UIColor.init(hex: "EB7F33"), bubbleConfig: nil))
    }

    private func setupChart() {
        lineLinearChart = MLLineChart(frame: CGRect(x: 0, y: 0, width: 320, height: heightChart))
        lineLinearChart.translatesAutoresizingMaskIntoConstraints = false
        lineLinearChart.dataEntries = dataEntries
        lineLinearChart.minPoint = 0
        lineLinearChart.maxPoint = 7
        lineLinearChart.showAxisLine = true
        lineLinearChart.showHorizontalLines = true
        lineLinearChart.showDots = false
        lineLinearChart.lineColor = .lightGray
        lineLinearChart.horizontalLinesColor = .gray
        lineLinearChart.labelColor = .gray
        lineLinearChart.showBubbleInfo = false
        lineLinearChart.hasColoredLines = true
        lineLinearChart.labelBottomConfig = MLLabelConfig(color: .gray,
                                                          backgroundColor: .clear,
                                                          rounded: false,
                                                          font: UIFont.systemFont(ofSize: 11),
                                                          width: 16, height: 16, fontSize: 11)
        self.setupViewConfiguration()

    }

    public func animate() {
        lineLinearChart.scrollToTheEnd()
    }
    
    /// Cntinue your code
    
}

Docs

Documentation

MLLineChart Docs (42% documented)

Demo App

Clone: MLLineChartDemo

     

Contributing

Issues and pull requests are welcome!

Todo

  • Curved chart with colors on segments
  • Migrate to Swift 4.2
  • 100% documented

Author

Michel Anderson Lutz Teixeira @michel_lutz

Inspired on nhatminh12369/LineChart

My Site

Contributions

License

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