0

我有一个 plist(比如列表date and distance)。现在我希望将此 Plist 值填充到..但是Bar GraphECGraphECGraph 的示例代码..打印我需要每次分配ECGRaphItem但 Plist 值正在变化。它可能会有所不同在数字中......我无法分配 ECGRaphItem......bcz plist值每次都会增加......

ECGraph 代码取自 http://code.google.com/p/ecgraph/downloads/detail?name=ECGraphSample.zip

那么如何处理ECGraphItem *item1 = [[ECGraphItem alloc] init];plist 值...

-(void)ViewDidLoad{
CGContextRef _context = UIGraphicsGetCurrentContext();
ECGraph *graph = [[ECGraph alloc] initWithFrame:CGRectMake(10,10, 480, 320) 
                                    withContext:_context isPortrait:NO];
ECGraphItem *item1 = [[ECGraphItem alloc] init];
item1.isPercentage = YES;
item1.yValue = 80;
item1.width = 35;
item1.name = @"A";

ECGraphItem *item2 = [[ECGraphItem alloc] init];
item2.isPercentage = YES;
item2.yValue = 35.3;
item2.width = 35;
item2.name = @"B";

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



NSArray *items = [[NSArray alloc] initWithObjects:item1,item2,item3,item4,item5,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 black]}
4

1 回答 1

2

希望它会对您有所帮助.. 首先,您必须将值转换为 int intValues 并将这些值传递到数组中..

 NSArray *percentage;

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame]))
{
    percentage=[[NSArray alloc]init];
    // Initialization code
}
return self;

}

-(void)setPercentage:(NSArray *)array
{
percentage =array;
}

- (void)drawRect:(CGRect)rect
{

NSLog(@"scoreforcelieng..%@",scoreforcelieng);
     // Drawing code
CGContextRef _context = UIGraphicsGetCurrentContext();

ECGraph *graph = [[ECGraph alloc] initWithFrame:CGRectMake(20,20,700, 423)
                                    withContext:_context isPortrait:YES];
ECGraphItem *item1 = [[ECGraphItem alloc] init];
item1.isPercentage = YES;

item1.yValue = [[percentage objectAtIndex:0]intValue];

item1.width = 35;
item1.name = @"whtever";

ECGraphItem *item2 = [[ECGraphItem alloc] init];
item2.isPercentage = YES;
 item2.yValue = [[percentage objectAtIndex:1]intValue];

item2.width = 35;
item2.name = @"whtever";

ECGraphItem *item3 = [[ECGraphItem alloc] init];
item3.isPercentage = YES;
 item3.yValue = [[percentage objectAtIndex:2]intValue];

item3.width = 35;
item3.name = @"whtever";

ECGraphItem *item4 = [[ECGraphItem alloc] init];
item4.isPercentage = YES;
 item4.yValue = [[percentage objectAtIndex:3]intValue];

item4.width = 35;
item4.name = @"whtever";

NSArray *items = [[NSArray alloc] initWithObjects:item1,item2,item3,item4,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]];

}

然后在你想用来显示图表的地方使用这些线

  NSArray *valueArray = [[NSArray alloc]initWithObjects:intValue1,intValue2,intValue3,intValue4,nil];
  NSLog(@"valueArray..%@",valueArray);
DisplayView *dView = [[DisplayView alloc]initWithFrame:CGRectMake(0, 0, 1024, 748)];
[dView setBackgroundColor:[UIColor whiteColor]];
 [dView setPercentage:valueArray]
于 2012-12-24T10:31:06.700 回答