我有 iphone 应用程序,我在其中使用 EASYGRAPH api 进行图表我创建了显示视图,我在其中绘制百分比和图表我希望其中的值可能在创建应用程序时动态出现。就像我有 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]];
}
图形视图控制器
- (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];
}