• This repository has been archived on 11/Aug/2020
  • Stars
    star
    449
  • Rank 97,328 (Top 2 %)
  • Language
    Objective-C
  • License
    Other
  • Created about 11 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive linecharts for the simplicity-loving iOS developer.

ios-linechart

Interactive linecharts for the simplicity-loving iOS developer.

You just want some linecharts, and Core Plot makes you think

fuuu

Search no more! ios-linechart is here!

Features

  • Simple API. Lets you draw the first chart by the time you would need to find sample code for Core Plot.
  • Interactivity. Lets users look at single datapoints.
  • Support non-uniform steps on the x axis

Installation

CocoaPods

The best way to get ios-linechart is to use CocoaPods.

Without CocoaPods

If, for some reason, you don't want that, copy the following files into your project:

  • LCLegendView.h, LCLegendView.m
  • LCLineChartView.h, LCLineChartView.m
  • LCInfoView.h, LCInfoView.m

Additionally, you will need to get some dependencies from the objc-utils project:

  • UIKit+DrawingHelpers.{h,m} (found in UIKit/Drawing/)

Just copy these into you project as well.

ios-linechart uses Core Graphics, so you'll need to add CoreGraphics.framework to your project.

Even if you don't use Cocoapods, it is recommended to use an official release, since the repository may be unstable in between releases. Just check out the newest tagged commit.

Usage

Basic usage can be seen in the demo app contained in the repository.

First, import the main header:

    #import "LCLineChartView.h"

Alternatively, you can import the abbreviation header, which provides names without the LC prefix:

    #import "LineChart.h"

Each chart line is contained in a LCLineChartData object, which specifies a range of its data on the x axis (xMin / xMax), a color, a title (which is displayed in the legend) and an itemCount, the number of data points:

    LCLineChartData *d = [LCLineChartData new];
    d.xMin = 1;
    d.xMax = 31;
    d.title = @"The title for the legend";
    d.color = [UIColor redColor];
    d.itemCount = 10;

Additionally, each LCLineChartData object also has a getData property. This is simply a block that takes the number of a data point as its argument and returns LCLineChartDataItem objects, which wrap the individual data points:

    NSMutableArray *vals = [NSMutableArray new];
    for(NSUInteger i = 0; i < d.itemCount; ++i) {
        [vals addObject:@((rand() / (float)RAND_MAX) * (31 - 1) + 1)];
    }
    [vals sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        return [obj1 compare:obj2];
    }];
    d.getData = ^(NSUInteger item) {
        float x = [vals[item] floatValue];
        float y = powf(2, x / 7);
        NSString *label1 = [NSString stringWithFormat:@"%d", item];
        NSString *label2 = [NSString stringWithFormat:@"%f", y];
        return [LCLineChartDataItem dataItemWithX:x y:y xLabel:label1 dataLabel:label2];
    };

The x and y properties of LCLineChartDataItem are, obviously, the x and y values of the data point. xLabel is the text displayed on the x axis when the data point is selected, dataLabel is usually just a textual representation of the y value, and is displayed in a bubble directly next to the data point when the user touches it.

Note that, to get a coherent chart, the x values for the items should be sorted. This will be the case anyway for most real-world data.

Finally, everything is packed up into a LCLineChartView:

    LCLineChartView *chartView = [[LCLineChartView alloc] initWithFrame:CGRectMake(20, 700, 500, 300)];
    chartView.yMin = 0;
    chartView.yMax = powf(2, 31 / 7) + 0.5;
    chartView.ySteps = @[@"0.0",
                         [NSString stringWithFormat:@"%.02f", chartView.yMax / 2],
                         [NSString stringWithFormat:@"%.02f", chartView.yMax]];
    chartView.data = @[d];

    [self.view addSubview:chartView];

The yMin and yMax properties should be self-evident. ySteps is an array of labels which are placed along the y axis. data is an array of all LineChartData objects to use. drawsDataPointOrnaments is a switch that determines whether circles are drawn around the actual data points.

Screenshots

Screenshot 1 FOSSA Status

Screenshot 2

FAQ

  • The sample project doesn't compile

    The sample project, at the moment, needs CocoaPods. Install Cocoapods, then run pod install while you are in the ios-linechart directory.

  • Will the project support bar charts, pie charts, ...?

    No.

Contact

Travis CI build status

Bug reports and pull requests are welcome! Contact me via e-mail or just by opening an issue on GitHub.

License

FOSSA Status

More Repositories

1

objc-utils

Utilities for developing ObjC, particularly under iOS
Objective-C
142
star
2

IAPManager

Yet Another simple in-app purchase interface
Objective-C
139
star
3

HoudiniFlatThemes

Flat themes for Houdini
36
star
4

uiview-hierarchical-drawing

Draw UIView hierarchy manually, for crisp rendering of PDFs from views in iOS
Objective-C
32
star
5

mrAiVexShader

Houdini VEX/CVEX shader for Arnold
C++
30
star
6

mrAiHouOceanShader

Shader to render Houdini ocean spectra natively in Arnold
C++
27
star
7

objc-simple-bindings

A simple bindings mechanism for Objective-C
Objective-C
21
star
8

CDJSONExporter

Conversion of a Core Data Store to/from JSON.
Objective-C
15
star
9

ios-NumberRangeSelector

Granular selection from a numeric range for iOS.
Objective-C
13
star
10

ofxPoissonDiskSampling

Poisson Disk Sampling for openFrameworks.
C++
13
star
11

ofxDelaunay2D

2D Delaunay triangulation of a set of points for OpenFrameworks
C++
11
star
12

houdini-principal-curvature

Houdini SOP for principal curvature directions
C++
7
star
13

Hs-Game

A Haskell library for basic game theory
Haskell
7
star
14

ofxGpuThicklines

Thick line drawing on the GPU for openFrameworks.
C++
7
star
15

uikit-utils

Utilities for UIKit
Objective-C
7
star
16

houdini-transform-matcher

A Houdini DSO that extracts the transform between two sets of points.
C++
6
star
17

ofxGpuCurves

openFrameworks addons to render large amounts of Catmull-Rom splines on the GPU
C++
5
star
18

CoreDataValidation

Validation for Core Data objects
Objective-C
4
star
19

Delaunay

Generates a Delaunay triangulation of a set of points
Haskell
2
star
20

ios-versioncheck

Quick, cached version checking for iOS
Objective-C
2
star
21

ios-notificationmanager

Sane management of local notifications
Objective-C
1
star
22

blaze-html-truncate

A HTML truncator for Haskell
Haskell
1
star
23

PHCPack-hs

A simple Haskell wrapper of the PHCPack solver for polynomial systems
Haskell
1
star
24

HOpenVGRaw

OpenVG / ShivaVG bindings
Haskell
1
star
25

miWorleyNoise

Worley noise / Voronoi noise shader for mental ray
C
1
star