0

グラフにEASYGRAPHAPIを使用しているiPhoneアプリがあります。パーセンテージとグラフチャートを描画する表示ビューを作成しています。アプリの作成時にこの値が動的に表示されるようにします。パーセンテージが78%の場合と同様に、これをどのように割り当てる必要がありますか。表示ビューに対する私のコードの別のビューである値

表示ビュー

 #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;

パーセンテージを次のようにtotoalpercentageに設定したいのですが、GraohsViewCOntrollerにあり、そのninはDisplayViewです。

このような

    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];

   }
4

1 に答える 1

0

すべてのアイテムのパーセンテージを DisplayView に渡す必要がある場合は、DisplayView でメソッドを作成し、

-(void) setPercentageArray:(NSArray*) 配列

次に、GraphsViewController からこのメソッドを呼び出して、次のように配列を渡します。

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

DisplayView でクラス メンバー変数を作成し、'setPercentageArray' このメソッドがその変数を設定します。

その配列をそれぞれのアイテムに使用します。

編集:

DisplayView の .h で

@interface Display : UIView {

 NSArray *percentages;

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

DisplayView.m に、このメソッドを追加し、

-(void) setPercentageArray:(NSArray*) array
{
    percentages = array;
}

drawRect メソッドでは、次のようにできます。

 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";
于 2012-05-14T11:34:02.167 に答える