iphone自适应三维柱状图

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 05:07 点击:

点击柱状图中的 柱 可获取 该柱的编号(从左到右,0-n)
能自动调整 柱 的宽度以及各 柱 之间的间隔
 
  1 //
  2 //  NTChartView.m
  3 //  chart
  4 //
  5 //  Created by wml on 11-04-10.
  6 //  Copyright 2009 __MyCompanyName__. All rights reserved.
  7 //
  8
  9 #import "NTChartView.h"
 10 #import "Alerter.h"
 11 #import "Rectangle.h"
 12
 13 static int MARGIN_LEFT = 50;
 14 static int MARGIN_BOTTOM = 30;
 15 static int MARGIN_TOP = 20;
 16 static int SHOW_SCALE_NUM = 7;
 17 static int WIDTH = 300;
 18 static int HEIGHT = 300;
 19
 20 @interface NTChartView(private)
 21 -(void)drawColumn:(CGContextRef)context rect:(CGRect)_rect;
 22 -(void)drawScale:(CGContextRef)context rect:(CGRect)_rect;
 23 -(void)calcScales:(CGRect)_rect;
 24 @end
 25
 26 @implementation NTChartView
 27 @synthesize groupData;
 28 @synthesize groupRect;
 29 @synthesize frstTouch;
 30 @synthesize scndTouch;
 31
 32 - (void) dealloc
 33 {
 34     [groupRect release];
 35     [groupData release];
 36     [super dealloc];
 37 }
 38
 39
 40 -(void)drawRect:(CGRect)_rect{
 41     WIDTH = _rect.size.width;
 42     HEIGHT = _rect.size.height;
 43     groupRect = [[NSMutableArray alloc] init];
 44     MARGIN_LEFT = WIDTH/6.0;
 45     MARGIN_BOTTOM = HEIGHT/10.0;
 46     MARGIN_TOP = HEIGHT/15.0;
 47    
 48     // the _rect is the Canvas on which the bar chart should be painted
 49    
 50     //绘图上下文
 51     CGContextRef context = UIGraphicsGetCurrentContext();
 52     //设置画笔颜色
 53     CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
 54     //为该矩形填充颜色
 55     CGContextFillRect(context, _rect);
 56    
 57     //计算刻度
 58     [self calcScales:_rect];
 59     //画刻度
 60     [self drawScale:context rect:_rect];
 61     //画柱
 62     [self drawColumn:context rect:_rect];
 63    
 64 }
 65
 66 -(void)drawScale:(CGContextRef)context rect:(CGRect)_rect{
 67    
 68     //the coordinate axis
 69     CGPoint points[3];
 70     // the top "end" of the y-axis
 71     points[0] = CGPointMake(MARGIN_LEFT - WIDTH/30, MARGIN_TOP);
 72     // the coordinate center
 73     points[1] = CGPointMake(MARGIN_LEFT -WIDTH/30, _rect.size.height - MARGIN_BOTTOM + 1);
 74     // the right "end" of x-axis
 75     points[2] = CGPointMake(_rect.size.width - WIDTH/30, _rect.size.height - MARGIN_BOTTOM + 1);
 76     CGContextSetAllowsAntialiasing(con

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Lexical or Preprocessor Issue 'xxx.h
      • ios学习笔记(二)xcode 4.3.2下实现基本交互
      • ios版本的helloworld
      • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
      • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
      • IOS类似iphone通讯录TableView的完整demo【附源码】
      • UITableView一些方法
      • [iPhone中级]iPhone团购信息客户端的开发 (二)
      • 如何为Iphone应用创建启动界面
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1