图表(ECGraph)从Plist填充

时间:2012-12-24 09:32:12

标签: iphone ios graph plist

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

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

然后如何为plist值处理这个ECGRaphItem ...

ECGraphItem *item1 = [[ECGraphItem alloc] init];

1 个答案:

答案 0 :(得分:2)

希望它能帮到你..首先你需要将你的值转换为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]