iPhone - ECGraph将我的图形绘制为Y轴上的单行

时间:2012-04-24 09:39:36

标签: ios4 graph

我正在使用Xcode 3.2.3和iOS 4 SDK。

我正准备一个小应用程序来绘制图表上的值。为此,我使用了ECGraph库。我下载了示例应用程序并调整了一下以满足我的目的。我希望图表以小时为单位绘制X轴上的时间,在Y轴上绘制一个简单的int值。

我的问题:当我选择在ECGraph中创建一个点的选项为(日期,值)时,如果X轴上的刻度,即时间单位是日期,我可以看到图形。如果我将时间单位更改为HOUR,则图表是Y轴上的单行,其中Y轴图是正确的,但X轴点始终是原点。

graph shown is not as expected, pt 2 is (9, 13)

我在这里添加了我的UIView文件中的代码。它只是从演示应用程序中获取的一个,随着ECGraph lib下载,然后调整我的东西。

DisplayView.m:

    //
    //  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

0 个答案:

没有答案