GithubHelp home page GithubHelp logo

meway24 / teachart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xhacker/teachart

0.0 1.0 0.0 397 KB

Simple and intuitive iOS chart library. Contribution graph, clock chart, and bar chart.

License: MIT License

teachart's Introduction

TEAChart

Version License Platform

Simple and intuitive iOS chart library, for Pomotodo app. Contribution graph, clock chart, and bar chart.

Supports Storyboard.

Usage

See the header files for complete documents.

Contribution Graph

Contribution Graph

The contribution graph mimics the GitHub one. You can implement the TEAContributionGraphDataSource to customize the style of the graph. The methods required to customize it are:

// The DataSource should return an NSDate that occurs inside the month to graph
- (NSDate *)monthForGraph;

// The day variable is an integer from 1 to the last day of the month given by monthForGraph
// Return the value to graph for each calendar day or 0.
- (NSInteger)valueForDay:(NSUInteger)day;

There are currently three more DataSource methods to customize the coloring of the graph. Each grade is represented by a different color.

// Defines the number of distinct colors in the graph
- (NSUInteger)numberOfGrades;

// Defines what color should be used by each grade.
- (UIColor *)colorForGrade:(NSUInteger)grade;

// Defines the cutoff values used for translating values into grades.
// For example, you may want different grades for the values grade==0, 1 <= grade < 5, 5 <= grade.
// This means there are three grades total
// The minimumValue for the first grade is 0, the minimum for the second grade is 1, and the minimum for the third grade is 5
- (NSInteger)minimumValueForGrade:(NSUInteger)grade;

Here is a simple sample of implementing the DataSource required methods after connecting the DataSource in InterfaceBuilder. I will add delegate methods to adjust the width and spacing in a future release.

// This sample uses Storyboard
@property (weak, nonatomic) IBOutlet TEAContributionGraph *contributionGraph;

// Contribution graph
self.contributionGraph.width = 12;
self.contributionGraph.spacing = 6;

#pragma mark - TEAContributionGraphDataSource Methods
- (NSDate *)monthForGraph
{
	// Graph the current month
    return [NSDate date];
}

- (NSInteger)valueForDay:(NSUInteger)day
{
	// Return 0-5
    return day % 6;
}

Clock Chart

Clock Chart

// This sample uses Storyboard
@property (weak, nonatomic) IBOutlet TEAClockChart *clockChart;

self.clockChart.data = @[
    [TEATimeRange timeRangeWithStart:[NSDate date] end:[NSDate dateWithTimeIntervalSinceNow:3600]],
    // ...
];

Bar Chart

Bar Chart

Just a bar chart, no label, no interaction, no animation.

#import "TEAChart.h"

TEABarChart *barChart = [[TEABarChart alloc] initWithFrame:CGRectMake(20, 20, 100, 40)];
barChart.data = @[@2, @7, @1, @8, @2, @8];
[self.view addSubview:barChart];

Colored Bar Chart

To add colors to the bar chart, add an array of colors

#import "TEAChart.h"

TEABarChart *barChart = [[TEABarChart alloc] initWithFrame:CGRectMake(20, 20, 100, 40)];
barChart.barColors = @[[UIColor orangeColor], [UIColor yellowColor], [UIColor greenColor], [UIColor blueColor]];
barChart.data = @[@2, @7, @1, @8, @2, @8];
[self.view addSubview:barChart];

Installation

Use CocoaPods:

pod 'TEAChart'

Or drag TEAChart folder into your project.

Contribution

Pull requests are welcome! If you want to do something big, please open an issue first.

License

MIT

teachart's People

Contributors

xhacker avatar joeblau avatar

Watchers

Meway 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.