Skip to content

Latest commit

 

History

History
127 lines (98 loc) · 7.19 KB

README.md

File metadata and controls

127 lines (98 loc) · 7.19 KB

Logo

Attention, this project is without maintenance

Simple and dynamic bar graph, very easy setup and operation.

Preview

Preview Preview Preview Preview Preview Preview Preview Preview

##Requirements and Dependencies

  • iOS >= 6.0
  • ARC enabled

##Installation

####CocoaPods: #####Building pod 'HACBarChart'

####Manual install:

  • Copy HACBarChart.h HACBarChart.m HACBarLayer.h and HACBarLayer.m to your project
  • Manual install HACBarChart

##Usage

To make it graphically xib or storyboard, add a UIView and assign a subclass of HACBarChart. Allocate the required constraints should be necessary and appropriate measures according to our needs. The next step would be a sight IBOutlet to assign attributes and data. Once these steps, we pass the data we want to paint in the graph, it is an NSArray of NSDictionary, and the keys they should be as in the example I show below. The keys kHACColor and kHACCustomText is optional but kHACPercentage is required.

#import "HACBarChart.h"

@interface ViewController (){
    NSArray *data;
}

@property (weak, nonatomic) IBOutlet HACBarChart *chart;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    data = @[
             @{kHACPercentage:@1000, kHACColor  : [UIColor colorWithRed:0.000f green:0.620f blue:0.890f alpha:1.0f], kHACCustomText : @"January"},
             @{kHACPercentage:@875,  kHACColor  : [UIColor colorWithRed:0.431f green:0.000f blue:0.533f alpha:1.0f], kHACCustomText : @"February"},
             @{kHACPercentage:@875,  kHACColor  : [UIColor colorWithRed:0.922f green:0.000f blue:0.000f alpha:1.0f], kHACCustomText : @"March"},
             @{kHACPercentage:@875,  kHACColor  : [UIColor colorWithRed:0.000f green:0.671f blue:0.180f alpha:1.0f], kHACCustomText : @"April"},
             @{kHACPercentage:@750,  kHACColor  : [UIColor colorWithRed:1.000f green:0.000f blue:0.851f alpha:1.0f], kHACCustomText : @"May"},
             @{kHACPercentage:@750,  kHACColor  : [UIColor colorWithRed:1.000f green:0.808f blue:0.000f alpha:1.0f], kHACCustomText : @"June"},
             @{kHACPercentage:@625,  kHACColor  : [UIColor colorWithRed:0.294f green:0.843f blue:0.251f alpha:1.0f], kHACCustomText : @"July"},
             @{kHACPercentage:@500,  kHACColor  : [UIColor colorWithRed:1.000f green:0.404f blue:0.000f alpha:1.0f], kHACCustomText : @"August"},
             @{kHACPercentage:@500,  kHACColor  : [UIColor colorWithRed:0.282f green:0.631f blue:0.620f alpha:1.0f], kHACCustomText : @"September"},
             @{kHACPercentage:@375,  kHACColor  : [UIColor colorWithRed:0.776f green:0.000f blue:0.702f alpha:1.0f], kHACCustomText : @"October"},
             @{kHACPercentage:@250,  kHACColor  : [UIColor colorWithRed:0.282f green:0.631f blue:0.620f alpha:1.0f], kHACCustomText : @"November"},
             @{kHACPercentage:@125,  kHACColor  : [UIColor colorWithRed:0.776f green:0.000f blue:0.702f alpha:1.0f], kHACCustomText : @"December"}
             ];
             
    // Assign data   
    _chart.data = data;
}

For draw the chart, after assign the data is necessary doing in the method viewDidAppear, as in the following example

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    [_chart draw];
}

##Customize

    ////// CHART CUSTOMIZE
    _chart.showAxis                 = YES;   // Show axis line
    _chart.showProgressLabel        = YES;   // Show text for bar
    _chart.vertical                 = YES;   // Orientation chart
    _chart.reverse                  = NO;   // Orientation chart
    _chart.showDataValue            = YES;   // Show value contains _data, or real percent value
    _chart.showCustomText           = YES;   // Show custom text, in _data with key kHACCustomText
    _chart.barsMargin               = 0;     // Margin between bars
    _chart.sizeLabelProgress        = 30;    // Width of label progress text
    _chart.numberDividersAxisY      = 8;
    _chart.animationDuration        = 2;
//    _chart.axisMaxValue             = 1500;    // If no define maxValue, get maxium of _data
    _chart.progressTextColor        = [UIColor darkGrayColor];
    _chart.axisYTextColor           = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0];
    _chart.progressTextFont         = [UIFont fontWithName:@"DINCondensed-Bold" size:6];
    _chart.typeBar                  = HACBarType2;
    _chart.dashedLineColor            = [UIColor colorWithRed:0.44 green:0.66 blue:0.86 alpha:.3];
    _chart.axisXColor                 = [UIColor colorWithRed:0.44 green:0.66 blue:0.86 alpha:1.0];
    _chart.axisYColor                 = [UIColor colorWithRed:0.44 green:0.66 blue:0.86 alpha:1.0];
    _chart.data = data;
    
    ////// CHART SET DATA
    [_chart draw];
    
    

Enjoy :D

Contributing

  1. Fork it ( https://github.com/[my-github-username]/HACBarChart/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request