How to hide graph on button click ?
Posted
by aman-gupta
on Stack Overflow
See other posts from Stack Overflow
or by aman-gupta
Published on 2010-04-26T05:51:56Z
Indexed on
2010/04/26
5:53 UTC
Read the original article
Hit count: 349
iphone
Hi,
In my application I m using following codes to draw a graph but I want that graph will be displayed on button click :-
import
@interface frmGraphView : UIView {
}
@end
///////////////////// // // frmGraphView.m // UV Alarm // // Created by Aman on 4/4/10. // Copyright 2010 MyCompanyName. All rights reserved. //
import "frmGraphView.h"
@implementation frmGraphView
struct TCo_ordinates { float x; float y; };
- (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self; }
/* // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } */
/* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */
-(void)drawHGrid { //struct gridForXYaxis *gridForX = (struct gridForX *) calloc(sizeof(struct gridFor)) }
(void)drawRect:(CGRect)rect {
ifdef _DEBUG
NSLog(@"frmGraph_drawRect_start");
endif
CGContextRef ctx = UIGraphicsGetCurrentContext();
struct TCo_ordinates *tCoordianates; //creating the object of structure. float fltX1,fltX2,fltY1,fltY2=0; //Dividing the Y-axis
ifdef _DEBUG
NSLog(@"Start drawing Y-Axis");
endif
fltX1 = 25; fltY1 = 2; fltX2 = fltX1; fltY2 = 254; //CGContextSetRGBStrokeColor(ctx, 2.0, 2.0, 2.0, 1.0); CGContextSetLineWidth(ctx, 2.0); CGContextMoveToPoint(ctx, fltX1, fltY1); CGContextAddLineToPoint(ctx, fltX2, fltY2); NSArray *hoursInDays = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", nil]; NSMutableArray *yAxisCoordinates = [[[NSMutableArray alloc] init] autorelease]; for(int intIndex = 0 ; intIndex < [hoursInDays count] ; fltY2-=20, intIndex++) {
ifdef _DEBUG
NSLog(@"Start of the partition of y axis");
endif
//CGContextSetRGBStrokeColor(ctx, 2, 2, 2, 1); //CGContextSetRGBStrokeColor(ctx, 1.0f/255.0f, 1.0f/255.0f, 1.0f/255.0f, 1.0f); //to draw the black line. CGContextMoveToPoint(ctx, fltX1-3 , fltY2-20); CGContextAddLineToPoint(ctx, fltX1+3, fltY2-20); CGContextSelectFont(ctx, "Helvetica", 12.0, kCGEncodingMacRoman); CGContextSetTextDrawingMode(ctx, kCGTextFill); //CGContextSetRGBFillColor(ctx, 0, 255, 255, 1); CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor); CGAffineTransform xform = CGAffineTransformMake( 1.0, 0.0, 0.0, -1.0, 0.0, 0.0); CGContextSetTextMatrix(ctx, xform); const char *arrayDataForYAxis = [[hoursInDays objectAtIndex:intIndex] UTF8String]; CGContextShowTextAtPoint(ctx,fltX1-20 , fltY2-15, arrayDataForYAxis, strlen(arrayDataForYAxis)); CGContextStrokePath(ctx);
ifdef _DEBUG
NSLog(@"End of the partition of graph");
endif
//NSValue *yAxis = [NSValue valueWithCGPoint:CGPointMake((tCoordianates->x = fltX1-21), (tCoordianates->y = fltY2-20))]; // [yAxisCoordinates addObject:yAxis];
ifdef _DEBUG
// NSLog(@"The value of yAxisCoordintes: %@", yAxisCoordinates);
endif
}
ifdef _DEBUG
NSLog(@"End of drawing Y-Axis");
endif
//Dividing the X-axis
ifdef _DEBUG
NSLog(@"Start drawing X-Axis");
endif
fltX1 = 25;
fltY1 = 255;
fltX2 = 320;
fltY2 = fltY1;
CGContextMoveToPoint(ctx, fltX1, fltY1);
CGContextAddLineToPoint(ctx, fltX2, fltY2);
//CGContextSetRGBStrokeColor(ctx, 2, 2, 2, 1);
CGContextSetLineWidth(ctx, 2.0);
NSArray *weekDays =[[NSArray alloc] initWithObjects:@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat", nil];
NSMutableArray *xAxisCoordinates = [[[NSMutableArray alloc] init] autorelease];
for(int intIndex = 0 ; intIndex < [weekDays count] ; fltX1+=40, intIndex++)
{
//CGContextSetRGBStrokeColor(ctx, 2, 2, 2, 1);
//CGContextSetStrokeColorWithColor(ctx, [UIColor orangeColor].CGColor);
CGContextMoveToPoint(ctx, fltX1+40 , fltY2-3);
CGContextAddLineToPoint(ctx, fltX1+40, fltY2+3);
CGContextSelectFont(ctx, "Italic", 12.0, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(ctx, kCGTextFill);
CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor);
CGAffineTransform xform = CGAffineTransformMake(
1.0, 0.0,
0.0, -1.0,
0.0, 0.0);
CGContextSetTextMatrix(ctx, xform);
const char *arrayDataForXAxis = [[weekDays objectAtIndex:intIndex] UTF8String];
CGContextShowTextAtPoint(ctx, fltX1+27, fltY2+20 , arrayDataForXAxis, strlen(arrayDataForXAxis));
CGContextStrokePath(ctx);
ifdef _DEBUG
NSLog(@"End of drawing X-Axis");
endif
//NSValue *xAxis = [NSValue valueWithCGPoint:CGPointMake((tCoordianates->x = fltX1+40), (tCoordianates->y = fltY2+18))];
// [xAxisCoordinates addObject:xAxis];
ifdef _DEBUG
//NSLog(@"The value of xAxisCoordintes: %@", xAxisCoordinates);
NSLog(@"frmGraph_drawRect_end");
endif
}
CGContextSetLineWidth(ctx, 10.0);
fltX1 = 25;
fltY1 = 235;
fltX2 = 320;
fltY2 = fltY1;
NSArray *coordinate1 = [[NSArray alloc] initWithObjects:@"65",@"105",@"145",@"185",@"225",@"265",@"305",nil];
NSArray *coordinate2 = [[NSArray alloc] initWithObjects:@"214",@"174",@"154",@"134",@"114",@"74",@"34",nil];
ifdef _DEBUG
NSLog(@"Fuction of Bar_start");
endif
for(int intIndex = 0; intIndex < [coordinate1 count], intIndex < [coordinate2 count]; fltX1+=40, intIndex++)
{
//CGContextSetRGBFillColor(ctx, 0, 0, 245, 1);
CGContextMoveToPoint(ctx, fltX1+40, fltY2+19);
const char *arrayDataForCoordinate1 = [[coordinate1 objectAtIndex:intIndex] UTF8String];
const char *arrayDataForCoordinate2 = [[coordinate2 objectAtIndex:intIndex] UTF8String];
CGContextAddLineToPoint(ctx, (atof(arrayDataForCoordinate1)), atof(arrayDataForCoordinate2));
}
ifdef _DEBUG
NSLog(@"Fuction of Bar_end");
endif
CGContextClosePath(ctx);
CGContextStrokePath(ctx);
[hoursInDays release];
[weekDays release];
[coordinate1 release];
[coordinate2 release];
hoursInDays = nil;
weekDays = nil;
coordinate1 = nil;
coordinate2 = nil;
} - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
(void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; }
(void)dealloc { [super dealloc]; }
@end
please help me out its urgent
© Stack Overflow or respective owner