2012-05-14 26 views
0

我在裏面我是用EASYGRAPH API爲圖我已經顯示視圖創建iPhone應用程序在那裏我得出的百分比和座標圖,我想在這一點,值可能會動態當應用程序是created.Like我有perecentage 78%,那麼應該如何分配此值這是在我的代碼顯示視圖anohter視圖如何assing從其他視圖控制器值自定義的UIView在iphone

顯示視圖

#import <UIKit/UIKit.h> 
@interface Display : UIView { 

} 

@end 



    #import "Display.h" 
    #import "ECGraph.h" 
@implementation Display 


- (id)initWithFrame:(CGRect)frame { 

self = [super initWithFrame:frame]; 
if (self) { 
    // Initialization code. 
} 
return self; 
    } 


- (void)drawRect:(CGRect)rect { 
// Drawing code 


CGContextRef _context = UIGraphicsGetCurrentContext(); 

ECGraph *graph = [[ECGraph alloc] initWithFrame:CGRectMake(500,-320,320, 200) withContext:_context isPortrait:NO]; 


ECGraphItem *item1 = [[ECGraphItem alloc] init]; 
item1.isPercentage = YES; 
item1.yValue = 80; 

我想要的百分比在下面設置這是在我的GraohsView控制器,它的nin是DisplayView的方式totoalpercentage

喜歡這張

item1.yValue=totalpercentage; 
item1.width = 35; 
item1.name = @"item1"; 

ECGraphItem *item2 = [[ECGraphItem alloc] init]; 
item2.isPercentage = YES; 
item2.yValue =17; 
item2.width = 35; 
item2.name = @"item2"; 
/* 
ECGraphItem *item3 = [[ECGraphItem alloc] init]; 
item3.isPercentage = YES; 
item3.yValue = 45; 
item3.width = 35; 
item3.name = @"item3"; 

ECGraphItem *item4 = [[ECGraphItem alloc] init]; 
item4.isPercentage = YES; 
item4.yValue = 78.6; 
item4.width = 35; 
item4.name = @"item4"; 

ECGraphItem *item5 = [[ECGraphItem alloc] init]; 
item5.isPercentage = YES; 
item5.yValue = 94.45; 
item5.width = 35; 
item5.name = @"item5"; */ 


NSArray *items = [[NSArray alloc] initWithObjects:item1,item2,nil]; 
[graph setXaxisTitle:@"name"]; 
[graph setYaxisTitle:@"Percentage"]; 
[graph setGraphicTitle:@"Histogram"]; 
[graph setDelegate:self]; 
[graph setBackgroundColor:[UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1]]; 
[graph drawHistogramWithItems:items lineWidth:2 color:[UIColor blackColor]]; 

    } 

GraphicsViewController

- (void)viewDidLoad { 
    [super viewDidLoad]; 

[self createGraph]; 

NSArray *percentages = [NSArray arrayWithObjects:@"80",@"17", nil]; 

[display setPercentageArray:percentages]; 
float costtoclient=[costToClient floatValue]; 
float markup=[clinicalMarkup floatValue]; 
float ProfitForCerenia=costtoclient/markup; 
    float totalProfit=costtoclient-ProfitForCerenia; 
int result = (int)ceilf(totalProfit); 
    NSString*cerniaProfitTitle=[NSString stringWithFormat:@"%d",result]; 
[profitForEachCereniaButton setTitle:cerniaProfitTitle forState:UIControlStateNormal]; 

int one=[valueOne intValue]; 
int two=[valueTwo intValue]; 
int three=[valueThree intValue]; 
int four=[valueFour intValue]; 
    int dogsPerMonthCarSickness=one+two+three+four; 
    int dogsPerYear=dogsPerMonthCarSickness*12; 
int annualprofit=dogsPerYear*result; 
NSString*annualProfitButtonTitle=[NSString stringWithFormat:@"%d",annualprofit]; 

[currentAnnualProfitFromCereniaButton setTitle:annualProfitButtonTitle forState:UIControlStateNormal]; 

int otherthancerenia=two+three+four; 
    int visitclinicpermonth=[perMonth intValue]; 
    int otherthanCereniaAnnaul=otherthancerenia*12; 

int potentialprofit=otherthanCereniaAnnaul*annualprofit; 

NSString*potentialProfitTitle=[NSString stringWithFormat:@"%d",potentialprofit]; 

[potentialProfit setTitle:potentialProfitTitle forState:UIControlStateNormal]; 

    int cereniaUsedForCarSickness=[cerenia intValue]; 
int cereniapercentageCal=cereniaUsedForCarSickness*100; 
     int cereniaPercentageCalculate=cereniapercentageCal/dogsPerMonthCarSickness; 
    NSString*cereniaUsedForCarSicknessTitle=[NSString stringWithFormat:@"%d",cereniaPercentageCalculate]; 

[cereniaUsedForMotionSicknessButton setTitle:cereniaUsedForCarSicknessTitle forState:UIControlStateNormal]; 


int otherthancereniaperc=100-cereniaPercentageCalculate; 

int otherthancereniapercentage=otherthancereniaperc; 


//int remaining=dogsPerMonthCarSickness-cereniaUsedForCarSickness; 
NSString*remainingTitle=[NSString stringWithFormat:@"%d",otherthancereniapercentage]; 

// [otherDrugsButton的setTitle:remainingTitle forState:UIControlStateNormal]; [otherDrugsButton setTitle:remainingTitle forState:UIControlStateNormal];

dogsPerYearForCarSickness=[NSString stringWithFormat:@"%d",dogsPerYear]; 


    [dogsPerYearForCarSicknessButton setTitle:dogsPerYearForCarSickness forState:UIControlStateNormal]; 


NSString *titledogsPerMonthForCarSicknessButton =[NSString stringWithFormat:@"%d",dogsPerMonthCarSickness]; 



[dogsPerMonthForCarSicknessButton setTitle:titledogsPerMonthForCarSicknessButton forState:UIControlStateNormal] 
    int visitclinicperyear=visitclinicpermonth*12; 

    float maxprofit=visitclinicperyear*0.17*result; 
int maximumprofit = (int)ceilf(maxprofit); 
NSString*maximumProfitTitle=[NSString stringWithFormat:@"%d",maximumprofit]; 
[maximumProfit setTitle:maximumProfitTitle forState:UIControlStateNormal]; 

} 

    -(void)createGraph{ 


PieClass *myPieClass=[[PieClass alloc]initWithFrame:CGRectMake(50,440,320,230)]; 

myPieClass.backgroundColor=[UIColor clearColor]; 

myPieClass.itemArray=[[NSArray alloc]initWithObjects:valueOne,valueTwo,valueThree,valueFour, nil]; 

myPieClass.myColorArray=[[NSArray alloc]initWithObjects:[UIColor blueColor],[UIColor redColor],[UIColor greenColor],[UIColor brownColor], nil]; 

myPieClass.radius=100; 

[self.view addSubview:myPieClass]; 

    } 

回答

0

,如果你需要通過每一個項目DisplayView的比例,使DisplayView的方法,

- (空)setPercentageArray:(NSArray的*)陣列

然後調用從GraphsViewController這種方法並傳遞數組,如

NSArray * percentages = [NSArray arrayWithObjects:@「80」,@「75」,@「90」,nil];

在DisplayView中創建類成員變量,'setPercentageArray'這個方法將設置該變量。

對各個項目使用該數組。

編輯:

在DisplayView.m .H DisplayView

@interface Display : UIView { 

NSArray *percentages; 

} 
-(void) setPercentageArray:(NSArray*) array; 
@end 

,加此法,

-(void) setPercentageArray:(NSArray*) array 
{ 
    percentages = array; 
} 
中的drawRect方法

,U可以這樣做,

ECGraphItem *item1 = [[ECGraphItem alloc] init]; 
item1.isPercentage = YES; 
item1.yValue = 80;  
item1.yValue= [percentages objectAtIndex:0]; 
item1.width = 35; 
item1.name = @"item1"; 

ECGraphItem *item2 = [[ECGraphItem alloc] init]; 
item2.isPercentage = [percentages objectAtIndex:1] 
item2.yValue =17; 
item2.width = 35; 
item2.name = @"item2"; 
+0

你可以寫一些代碼如何使這個請 – user1392981

+0

以及如何從GraphsViewController [self getPercantgeArray];調用此方法; – user1392981

+0

檢查編輯答案。 – waheeda

相關問題