Git Product home page Git Product logo

otpiechart's Introduction

OTPieChart

Did you ever dreamt to create really nice pie chart without the help of a good designer ?

Dream is over. We made it with love, just for you !

We made a demo project, feel free to test it.

Why OTPieChart

How to get it on your project ?

Add files to your project

It's really simple :

  • Download the project
  • Copy & Paste the pie chart folder into your project folder
  • Add the files in Xcode
  • Add QuartzCore framework to your project (Build phases of your target) like the following :

Add QuartzCore step 1

And then :

Add QuartzCore step 2

Now your project should build correctly.

Create a basic pie chart

Then, add the datasource and the delegate. Don't forget to import OTPieChartView.h :

#import "OTPieChartView.h" 

@interface ViewController : UIViewController <OTPieChartDataSource, OTPieChartDelegate>

@property (nonatomic, strong) NSArray        *slices;

And in the implementation file, copy & paste the following code :

- (void)viewDidLoad
{
	[super viewDidLoad];
	[bcNavigationController setCurrentDot:0];
	[bcNavigationController setMaximumDots:0];
	[bcNavigationController setNavigationMode:BCNavigationNavBar];
	// Do any additional setup after loading the view.
	
	NSArray *colors = [NSArray arrayWithObjects:
					   UIColorFromRGB(0x1a4ada),
					   UIColorFromRGB(0x3d40be),
					   UIColorFromRGB(0x6035a3),
					   UIColorFromRGB(0x832b87),
					   UIColorFromRGB(0xa6206c),
					   UIColorFromRGB(0xc91650),
					   UIColorFromRGB(0xec0b35),
					   UIColorFromRGB(0xea5601),
					   UIColorFromRGB(0xfeb003),
					   UIColorFromRGB(0xeacb01),
					   nil];

	CGFloat percentageValue = 0.1;
	NSString *label = [NSString stringWithFormat:@"Value : %.2f %%", percentageValue];
	
	NSMutableArray *tmpSlices = [NSMutableArray array];
	
	// Create the slices :
	for (UIColor *color in colors)
	{
		OTSlice *slice = [[OTSlice alloc] initWithLabel:label
										percentageValue:percentageValue
												  color:color];
		[tmpSlices addObject:slice];
	}

	self.slices = [NSArray arrayWithArray:tmpSlices];
	
	// Create the pie Chart
	
	OTPieChartView *pieChartView = [[OTPieChartView alloc] initWithFrame:CGRectMake(20, 20, 400, 400)];
	pieChartView.delegate = self;
	pieChartView.datasource = self;
	[self.view addSubview:pieChartView];
	[pieChartView loadPieChart];
}

/**************************************************************************************************/
#pragma mark - OTPieChartDatasource

- (NSUInteger)numbertOfSliceForPieChartIndex:(OTPieChartView *)thePieChart
{
	return self.slices.count;
}

- (CGFloat)pieChart:(OTPieChartView *)thePieChart getPercentageValue:(NSUInteger)pieChartIndex
{
	if ([self.slices count] > pieChartIndex)
	{
		OTSlice *slice = [self.slices objectAtIndex:pieChartIndex];
		return slice.percentageValue;
	}
	else
	{
		return 0.0;
	}
}

- (UIColor *)pieChart:(OTPieChartView *)thePieChart getSliceColor:(NSUInteger)pieChartIndex
{
	if ([self.slices count] > pieChartIndex)
	{
		OTSlice *slice = [self.slices objectAtIndex:pieChartIndex];
		return slice.color;
	}
	else
	{
		return nil;
	}
}

- (NSString *)pieChart:(OTPieChartView *)thePieChart getSliceLabel:(NSUInteger)pieChartIndex
{
	OTSlice *slice = [self.slices objectAtIndex:pieChartIndex];

	return slice.title;
}

/**************************************************************************************************/
#pragma mark - OTPieChartDelegate

- (void)pieChart:(OTPieChartView *)thePieChart didSelectSliceAtIndex:(NSUInteger)pieChartIndex
{
	NSLog(@"pie clicked : %d", pieChartIndex);
}

That's it !

Generate documentation

OTPieChart use AppleDoc to generate its doc.

In the Tools directory, you can find documentation.sh file. Edit it to set the correct path to your AppleDoc executable.

otpiechart's People

Contributors

bcharp avatar sprohaszka avatar

Watchers

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