Ios4 iPhone-ECGraph将我的图形绘制为Y轴上的一条直线
我将Xcode 3.2.3与iOS 4 SDK一起使用 我正在准备一个用于在图形上绘制值的小应用程序。为此,我使用了ECGraph库。我下载了示例应用程序,并对其进行了一些调整,以适合我的目的。我想让图表在X轴上以小时为单位绘制时间,在Y轴上绘制一个简单的int值 我的问题是:当我选择在ECGraph中创建一个点作为(日期,值)选项时,如果X轴上的比例,即时间单位是日期,我可以看到该图。如果我将时间单位更改为小时,则图形是Y轴上的一条直线,其中Y轴绘图是正确的,但X轴点始终是原点 我在这里添加了UIView文件中的代码。它只是一个从演示应用程序,提供了ECGraph库下载,然后为我的东西调整 DisplayView.m:Ios4 iPhone-ECGraph将我的图形绘制为Y轴上的一条直线,ios4,graph,Ios4,Graph,我将Xcode 3.2.3与iOS 4 SDK一起使用 我正在准备一个用于在图形上绘制值的小应用程序。为此,我使用了ECGraph库。我下载了示例应用程序,并对其进行了一些调整,以适合我的目的。我想让图表在X轴上以小时为单位绘制时间,在Y轴上绘制一个简单的int值 我的问题是:当我选择在ECGraph中创建一个点作为(日期,值)选项时,如果X轴上的比例,即时间单位是日期,我可以看到该图。如果我将时间单位更改为小时,则图形是Y轴上的一条直线,其中Y轴绘图是正确的,但X轴点始终是原点 我在这里添加
//
// DisplayView.m
// ECGraphic
//
// Created by ris on 10-4-17.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "DisplayView.h"
#import "ECCommon.h"
#import "ECGraphPoint.h"
#import "ECGraphLine.h"
#import "ECGraphItem.h"
@implementation DisplayView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef _context = UIGraphicsGetCurrentContext();
ECGraph *graph = [[ECGraph alloc] initWithFrame:CGRectMake(10, 50, 300, 350) withContext:_context isPortrait:YES];
ECGraphPoint *point7 = [[ECGraphPoint alloc] init];
point7.yValue = 7;
point7.xDateValue = [ECCommon dOfS:@"08" withFormat:kDEFAULT_HOUR_FORMAT];
ECGraphPoint *point8 = [[ECGraphPoint alloc] init];
point8.yValue = 13;
point8.xDateValue = [ECCommon dOfS:@"09" withFormat:kDEFAULT_HOUR_FORMAT];
ECGraphPoint *point9 = [[ECGraphPoint alloc] init];
point9.yValue = 1;
point9.xDateValue = [ECCommon dOfS:@"10" withFormat:kDEFAULT_HOUR_FORMAT];
ECGraphPoint *point10 = [[ECGraphPoint alloc] init];
point10.yValue = 3;
point10.xDateValue = [ECCommon dOfS:@"11" withFormat:kDEFAULT_HOUR_FORMAT];
//NSArray *pts3 = [[NSArray alloc] initWithObjects:point7,point8,point9, point10, nil];
NSArray *pts3 = [[NSArray alloc] initWithObjects:point7,point8, nil];
ECGraphLine *line3 = [[ECGraphLine alloc] init];
line3.isXDate = YES;
line3.points = pts3;
NSArray *lines = [[NSArray alloc] initWithObjects:line3,nil];
[graph setXaxisTitle:@"Hours"];
[graph setYaxisTitle:@"Energy consumed in Watts"];
[graph setGraphicTitle:@"Weekly consumption of your device"];
[graph setXaxisDateFormat:kDEFAULT_HOUR_FORMAT];
[graph setDelegate:self];
[graph setBackgroundColor:[UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1]];
[graph setPointType:ECGraphPointTypeCircle];
[graph drawCurveWithLines:lines lineWidth:2 color:[UIColor blackColor]];
}
- (void)dealloc {
[super dealloc];
}
@end
你找到解决办法了吗?你找到解决办法了吗?