Home

Awesome

MRBarChart

A simple scrollable bar chart based on UICollectionView

MRBarChart

###Installation

###Usage

MRBarChart follows the usual data source pattern. You view controller should implement the protocol MRBarChartDataSource. The following methods are mandatory:

- (NSInteger)numberOfBarsInChart:(MRBarChart *)chart {
    return 20;
}
- (CGFloat)barChart:(MRBarChart *)chart valueForBarAtIndex:(NSInteger)index {
    return 4.13;
}

Optionally, you can return a different color for each bar.

- (UIColor *)barChart:(MRBarChart *)chart colorForBarAtIndex:(NSInteger)index {
    return [UIColor redColor];
}

In order to calculate the proportianal height of each bar, you must set the maximum value for the chart:

_barChart.maxValue = 100.0;

###Storyboards

In addition to using the bar chart by doing [[MRChartView alloc] initWithFrame:...], if you are using storyboards you can simply drag a UIView into a view controller and set its class to MRBarChart.

Customization

The following properties are customizable:

Reloading

To reload the bar view call reloadData:(BOOL)animated.

Adding and removing bars can be done by using:

- (void)addBarAtIndex:(NSInteger)index animated:(BOOL)animated;
- (void)removeBarAtIndex:(NSInteger)index;

Check the sample project for documentation and usage options

###Delegate

Setting a delegate is optional and can be used to be notified when a bar is selected. Conform to the protocol MRBarChartDelegate and implement:

- (void)barChart:(MRBarChart *)chart didSelectBarAtIndex:(NSInteger)index;