-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHTViewController.m
More file actions
145 lines (117 loc) · 4.76 KB
/
Copy pathHTViewController.m
File metadata and controls
145 lines (117 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// HTViewController.m
// CorePlotProgram
//
// Created by wb-shangguanhaitao on 14-2-24.
// Copyright (c) 2014年 shangguan. All rights reserved.
//
#import "HTViewController.h"
#import "CorePlot-CocoaTouch.h"
@interface HTViewController ()<CPTPlotDataSource>
/**
* 设置图表绘制的配置
*/
- (void)setupCoreplotViews;
@end
@implementation HTViewController
#pragma mark - Superclass API
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupCoreplotViews];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Private API
- (void)setupCoreplotViews
{
CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[graph applyTheme:theme];
CPTXYPlotSpace *space = (CPTXYPlotSpace *)graph.defaultPlotSpace;
space.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"0.0f") length:CPTDecimalFromString(@"3.0f")];
space.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"0.0f") length:CPTDecimalFromString(@"3.0f")];
space.allowsUserInteraction = YES;
graph.paddingTop = 0.0f;
graph.paddingLeft = 0.0f;
graph.paddingBottom = 0.0f;
graph.paddingRight = 0.0f;
graph.plotAreaFrame.paddingTop = 50.0f;
graph.plotAreaFrame.paddingLeft = 50.0f;
graph.plotAreaFrame.paddingBottom = 50.0f;
graph.plotAreaFrame.paddingRight = 50.0f;
graph.plotAreaFrame.borderLineStyle = nil;
graph.plotAreaFrame.cornerRadius = 0.0f;
graph.plotAreaFrame.masksToBorder = NO;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.axisLineStyle = nil;
x.majorTickLineStyle = nil;
x.minorTickLineStyle = nil;
// x.majorIntervalLength = CPTDecimalFromDouble(5.0);
// x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0.0);
x.title = @"X Axis";
x.titleLocation = CPTDecimalFromFloat(1.5f);
x.titleOffset = 30.0f;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:0], [NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:2], nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", nil];
NSUInteger labelLocation = 0;
NSMutableSet *customLabels = [NSMutableSet setWithCapacity:[xAxisLabels count]];
for ( NSNumber *tickLocation in customTickLocations ) {
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
// newLabel.offset = x.labelOffset + x.majorTickLength;
newLabel.rotation = M_PI_4;
[customLabels addObject:newLabel];
}
x.axisLabels = customLabels;
CPTXYAxis *y = axisSet.yAxis;
y.axisLineStyle = nil;
y.majorTickLineStyle = nil;
y.minorTickLineStyle = nil;
y.title = @"Y Axis";
y.titleLocation = CPTDecimalFromFloat(1.5f);
y.titleOffset = 30.0f;
CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor orangeColor] horizontalBars:NO];
// barPlot.baseValue = CPTDecimalFromString(@"0.025f");
barPlot.barCornerRadius = 5.0f;
// barPlot.barBaseCornerRadius = 5.0f;
// barPlot.barWidthScale = 2.0f;
barPlot.dataSource = self;
[graph addPlot:barPlot];
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor whiteColor];
titleStyle.fontName = @"Helvetica-Bold";
titleStyle.fontSize = 16.0;
titleStyle.textAlignment = CPTTextAlignmentCenter;
graph.title = [NSString stringWithFormat:@"WhatsApp"];
graph.titleTextStyle = titleStyle;
graph.titleDisplacement = CGPointMake(0.0, -20.0);
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
//...
CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:hostingView];
hostingView.hostedGraph = graph;
}
#pragma makr - CPTPlotDataSource API
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return 3;
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx
{
if (fieldEnum == CPTScatterPlotFieldY)
{
return [NSNumber numberWithUnsignedInteger:idx + 1];
}
else
{
return [NSNumber numberWithUnsignedInteger:idx];
}
}
@end