質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Xcode 7

Xcode 7は、ソフトウェア開発のためのアップルの統合開発環境であるXcodeのバージョン。UIを作成するために用いるグラフィカルツールです。iOS9/OS X El Capitan/watchOS2に対応。Swift 2コンパイラーが搭載されています。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Q&A

0回答

1767閲覧

Objective-C core-plotでy=axのグラフ作成

gurennpaku

総合スコア12

Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Xcode 7

Xcode 7は、ソフトウェア開発のためのアップルの統合開発環境であるXcodeのバージョン。UIを作成するために用いるグラフィカルツールです。iOS9/OS X El Capitan/watchOS2に対応。Swift 2コンパイラーが搭載されています。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

0グッド

0クリップ

投稿2015/12/03 12:38

検索したのですがわからなかったので質問させてください
写真のようにシミュレータ上で数値を入力して「Calculation」を押すとグラフが変化するものが作りたいのですが、数値の入力する部分とCalculationの繋ぎ方がわかりません.
ここでaに数値を入力して

ご教授おねがいします。

Objective

1#import "ViewController.h" 2NSString *const kData = @"Data Source Plot"; 3@interface ViewController () 4 5 6 7@end 8@implementation ViewController 9 10// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 11- (void)viewDidLoad 12{ 13 [super viewDidLoad]; 14 15 self.scatterPlotData = [NSMutableArray array]; 16 17 for ( NSUInteger i = 0; i < 11; i++ ) { 18 NSNumber *x = [NSNumber numberWithDouble:i]; 19 NSNumber *y = [NSNumber numberWithDouble:ax]; 20 [self.scatterPlotData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]]; 21 } 22 23 // ホスティングビューを生成 24 CPTGraphHostingView *hostingView = 25 [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)]; 26 // 画面にホスティングビューを追加 27 [self.view addSubview:hostingView]; 28 29 // グラフを生成 30 graph = [[CPTXYGraph alloc] initWithFrame:hostingView.bounds]; 31 hostingView.hostedGraph = graph; 32 33 // グラフのボーダー設定 34 graph.plotAreaFrame.borderLineStyle = nil; 35 graph.plotAreaFrame.cornerRadius = 0.0f; 36 graph.plotAreaFrame.masksToBorder = NO; 37 38 // パディング 39 graph.paddingLeft = 0.0f; 40 graph.paddingRight = 0.0f; 41 graph.paddingTop = 0.0f; 42 graph.paddingBottom = 0.0f; 43 44 graph.plotAreaFrame.paddingLeft = 60.0f; 45 graph.plotAreaFrame.paddingTop = 60.0f; 46 graph.plotAreaFrame.paddingRight = 20.0f; 47 graph.plotAreaFrame.paddingBottom = 65.0f; 48 49 //プロット間隔の設定 50 CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 51 plotSpace.xScaleType = CPTScaleTypeLinear; 52 plotSpace.yScaleType = CPTScaleTypeLinear; 53 plotSpace.allowsUserInteraction = YES; 54 plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0.1) 55 length:CPTDecimalFromInt(10)]; 56 plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0.1) 57 length:CPTDecimalFromInt(10)]; 58 59 60 // テキストスタイル 61 CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle]; 62 textStyle.color = [CPTColor colorWithComponentRed:0.447f green:0.443f blue:0.443f alpha:1.0f]; 63 textStyle.fontSize = 13.0f; 64 textStyle.textAlignment = CPTTextAlignmentCenter; 65 66 // ラインスタイル 67 CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle]; 68 lineStyle.lineColor = [CPTColor colorWithComponentRed:0.788f green:0.792f blue:0.792f alpha:1.0f]; 69 lineStyle.lineWidth = 2.0f; 70 71 // X軸のメモリ・ラベルなどの設定 72 CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 73 CPTXYAxis *x = axisSet.xAxis; 74 x.axisLineStyle = lineStyle; // X軸の線にラインスタイルを適用 75 x.majorTickLineStyle = lineStyle; // X軸の大きいメモリにラインスタイルを適用 76 x.minorTickLineStyle = lineStyle; // X軸の小さいメモリにラインスタイルを適用 77 x.majorIntervalLength = CPTDecimalFromString(@"10"); // X軸ラベルの表示間隔 78 x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); // X軸のY位置 79 x.title = @"Incident Ion Energy[eV]"; 80 x.titleTextStyle = textStyle; 81 x.titleLocation = CPTDecimalFromFloat(40.0f);// タイトルの位置設定 82 x.titleOffset = 36.0f; 83 //x.minorTickLength = 5.0f; // X軸のメモリの長さ ラベルを設定しているため無効ぽい 84 //x.majorTickLength = 9.0f; // X軸のメモリの長さ ラベルを設定しているため無効ぽい 85 x.labelTextStyle = textStyle; 86 87 // Y軸のメモリ・ラベルなどの設定 88 CPTXYAxis *y = axisSet.yAxis; 89 y.axisLineStyle = lineStyle; // Y軸の線にラインスタイルを適用 90 y.majorTickLineStyle = lineStyle; // Y軸の大きいメモリにラインスタイルを適用 91 y.minorTickLineStyle = lineStyle; // Y軸の小さいメモリにラインスタイルを適用 92 y.majorTickLength = 9.0f; // Y軸の大きいメモリの長さ 93 y.minorTickLength = 5.0f; // Y軸の小さいメモリの長さ 94 y.majorIntervalLength = CPTDecimalFromFloat(1.0f); // Y軸ラベルの表示間隔 95 y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0.0f); // Y軸のX位置 96 y.title = @"Sputtering Yield[atoms/ion]"; 97 y.titleTextStyle = textStyle; 98 y.titleRotation = M_PI*2; 99 y.titleLocation = CPTDecimalFromFloat(8.0f); // タイトルの位置設定 100 y.titleOffset = 0.0f; 101 lineStyle.lineWidth = 0.1f; //y軸表示の線の大きさ 102 y.majorGridLineStyle = lineStyle; 103 y.labelTextStyle = textStyle; 104 105 // 折れ線グラフのインスタンスを生成 106 CPTScatterPlot *scatterPlot = [[CPTScatterPlot alloc] init]; 107 scatterPlot.identifier = kData; // 折れ線グラフを識別するために識別子を設定 108 scatterPlot.dataSource = self; // 折れ線グラフのデータソースを設定 109 110 // 折れ線グラフのスタイルを設定 111 CPTMutableLineStyle *graphlineStyle = [scatterPlot.dataLineStyle mutableCopy]; 112 graphlineStyle.lineWidth = 3; // 太さ 113 graphlineStyle.lineColor = [CPTColor colorWithComponentRed:0.573f green:0.82f blue:0.831f alpha:0.50f];// 色 114 scatterPlot.dataLineStyle = graphlineStyle; 115 116 // グラフに折れ線グラフを追加 117 [graph addPlot:scatterPlot]; 118 119 120} 121 122 123 124 125 126#pragma mark - 127#pragma mark Plot Data Source Methods 128 129// グラフに使用する折れ線グラフのデータ数を返す 130-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot 131{ 132 NSUInteger numRecords = 0; 133 NSString *identifier = (NSString *)plot.identifier; 134 135 // 折れ線グラフのidentifierにより返すデータ数を変える(複数グラフを表示する場合に必要) 136 if ( [identifier isEqualToString:kData] ) { 137 numRecords = self.scatterPlotData.count; 138 } 139 140 return numRecords; 141} 142 143// グラフに使用する折れ線グラフのX軸とY軸のデータを返す 144-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 145{ 146 NSNumber *num = nil; 147 NSString *identifier = (NSString *)plot.identifier; 148 149 // 折れ線グラフのidentifierにより返すデータ数を変える(複数グラフを表示する場合に必要) 150 if ( [identifier isEqualToString:kData] ) { 151 switch (fieldEnum) { 152 case CPTScatterPlotFieldX: // X軸の場合 153 num = [[self.scatterPlotData objectAtIndex:index] valueForKey:@"x"]; 154 break; 155 case CPTScatterPlotFieldY: // Y軸の場合 156 num = [[self.scatterPlotData objectAtIndex:index] valueForKey:@"y"]; 157 break; 158 } 159 } 160 161 return num; 162} 163 164@end 165 166

イメージ説明

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

domonr

2015/12/03 16:12

ViewはInterfaceBuilderを使用しているのでしょうか?
gurennpaku

2015/12/03 16:27

質問ありがとうございます。InterfaceBuilderを使用して作りたいです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問