質問編集履歴
1
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,4 +6,115 @@
|
|
6
6
|
|
7
7
|
おねがいします。下記にそのグラフの様子をのせます
|
8
8
|
|
9
|
-
](b89e327035153b24bb12e2a891252fa5.png)
|
9
|
+
](b89e327035153b24bb12e2a891252fa5.png)
|
10
|
+
|
11
|
+
グラフのソースコードを追加します
|
12
|
+
```Objective-C
|
13
|
+
- (void)viewDidLoad
|
14
|
+
{
|
15
|
+
[super viewDidLoad];
|
16
|
+
self.scatterPlotData = [NSMutableArray array];
|
17
|
+
|
18
|
+
for ( NSUInteger i = 0; i < 11; i++ ) {
|
19
|
+
NSNumber *x = [NSNumber numberWithDouble:i];
|
20
|
+
NSNumber *y = [NSNumber numberWithDouble:(int)(rand() / (double)RAND_MAX * 10)]; // 1〜10の値のランダム値(int)
|
21
|
+
[self.scatterPlotData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
|
22
|
+
}
|
23
|
+
|
24
|
+
// ホスティングビューを生成
|
25
|
+
CPTGraphHostingView *hostingView =
|
26
|
+
[[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
|
27
|
+
// 画面にホスティングビューを追加
|
28
|
+
[self.view addSubview:hostingView];
|
29
|
+
|
30
|
+
// グラフを生成
|
31
|
+
graph = [[CPTXYGraph alloc] initWithFrame:hostingView.bounds];
|
32
|
+
hostingView.hostedGraph = graph;
|
33
|
+
|
34
|
+
// グラフのボーダー設定
|
35
|
+
graph.plotAreaFrame.borderLineStyle = nil;
|
36
|
+
graph.plotAreaFrame.cornerRadius = 0.0f;
|
37
|
+
graph.plotAreaFrame.masksToBorder = NO;
|
38
|
+
|
39
|
+
// パディング
|
40
|
+
graph.paddingLeft = 0.0f;
|
41
|
+
graph.paddingRight = 0.0f;
|
42
|
+
graph.paddingTop = 0.0f;
|
43
|
+
graph.paddingBottom = 0.0f;
|
44
|
+
|
45
|
+
graph.plotAreaFrame.paddingLeft = 60.0f;
|
46
|
+
graph.plotAreaFrame.paddingTop = 60.0f;
|
47
|
+
graph.plotAreaFrame.paddingRight = 20.0f;
|
48
|
+
graph.plotAreaFrame.paddingBottom = 65.0f;
|
49
|
+
|
50
|
+
//プロット間隔の設定
|
51
|
+
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
|
52
|
+
//Y軸は0〜10の値で設定
|
53
|
+
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(10)];
|
54
|
+
//X軸は0〜10の値で設定
|
55
|
+
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(10)];
|
56
|
+
|
57
|
+
// テキストスタイル
|
58
|
+
CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle];
|
59
|
+
textStyle.color = [CPTColor colorWithComponentRed:0.447f green:0.443f blue:0.443f alpha:1.0f];
|
60
|
+
textStyle.fontSize = 13.0f;
|
61
|
+
textStyle.textAlignment = CPTTextAlignmentCenter;
|
62
|
+
|
63
|
+
// ラインスタイル
|
64
|
+
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
|
65
|
+
lineStyle.lineColor = [CPTColor colorWithComponentRed:0.788f green:0.792f blue:0.792f alpha:1.0f];
|
66
|
+
lineStyle.lineWidth = 2.0f;
|
67
|
+
|
68
|
+
// X軸のメモリ・ラベルなどの設定
|
69
|
+
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
|
70
|
+
CPTXYAxis *x = axisSet.xAxis;
|
71
|
+
x.axisLineStyle = lineStyle; // X軸の線にラインスタイルを適用
|
72
|
+
x.majorTickLineStyle = lineStyle; // X軸の大きいメモリにラインスタイルを適用
|
73
|
+
x.minorTickLineStyle = lineStyle; // X軸の小さいメモリにラインスタイルを適用
|
74
|
+
x.majorIntervalLength = CPTDecimalFromString(@"2"); // X軸ラベルの表示間隔
|
75
|
+
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); // X軸のY位置
|
76
|
+
x.title = @"X軸";
|
77
|
+
x.titleTextStyle = textStyle;
|
78
|
+
x.titleLocation = CPTDecimalFromFloat(5.0f);
|
79
|
+
x.titleOffset = 36.0f;
|
80
|
+
// x.minorTickLength = 5.0f; // X軸のメモリの長さ ラベルを設定しているため無効ぽい
|
81
|
+
// x.majorTickLength = 9.0f; // X軸のメモリの長さ ラベルを設定しているため無効ぽい
|
82
|
+
x.labelTextStyle = textStyle;
|
83
|
+
|
84
|
+
// Y軸のメモリ・ラベルなどの設定
|
85
|
+
CPTXYAxis *y = axisSet.yAxis;
|
86
|
+
y.axisLineStyle = lineStyle; // Y軸の線にラインスタイルを適用
|
87
|
+
y.majorTickLineStyle = lineStyle; // Y軸の大きいメモリにラインスタイルを適用
|
88
|
+
y.minorTickLineStyle = lineStyle; // Y軸の小さいメモリにラインスタイルを適用
|
89
|
+
y.majorTickLength = 9.0f; // Y軸の大きいメモリの長さ
|
90
|
+
y.minorTickLength = 5.0f; // Y軸の小さいメモリの長さ
|
91
|
+
y.majorIntervalLength = CPTDecimalFromFloat(1.0f); // Y軸ラベルの表示間隔
|
92
|
+
y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0.0f); // Y軸のX位置
|
93
|
+
y.title = @"Y軸";
|
94
|
+
y.titleTextStyle = textStyle;
|
95
|
+
y.titleRotation = M_PI*2;
|
96
|
+
y.titleLocation = CPTDecimalFromFloat(11.0f);
|
97
|
+
y.titleOffset = 15.0f;
|
98
|
+
lineStyle.lineWidth = 0.5f;
|
99
|
+
y.majorGridLineStyle = lineStyle;
|
100
|
+
y.labelTextStyle = textStyle;
|
101
|
+
|
102
|
+
// 折れ線グラフのインスタンスを生成
|
103
|
+
CPTScatterPlot *scatterPlot = [[CPTScatterPlot alloc] init];
|
104
|
+
scatterPlot.identifier = kData; // 折れ線グラフを識別するために識別子を設定
|
105
|
+
scatterPlot.dataSource = self; // 折れ線グラフのデータソースを設定
|
106
|
+
|
107
|
+
// 折れ線グラフのスタイルを設定
|
108
|
+
CPTMutableLineStyle *graphlineStyle = [scatterPlot.dataLineStyle mutableCopy];
|
109
|
+
graphlineStyle.lineWidth = 3; // 太さ
|
110
|
+
graphlineStyle.lineColor = [CPTColor colorWithComponentRed:0.573f green:0.82f blue:0.831f alpha:0.50f];// 色
|
111
|
+
scatterPlot.dataLineStyle = graphlineStyle;
|
112
|
+
|
113
|
+
// グラフに折れ線グラフを追加
|
114
|
+
[graph addPlot:scatterPlot];
|
115
|
+
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
```
|
120
|
+
ソースコードは少し変えていますが、このような感じです
|