現在coreplotを用いて折れ線グラフを作っているのですが軸設定の部分でエラーが発生して戸惑っております。
こちらが.hのソースコードです
Objective
1#import <UIKit/UIKit.h> 2#import "CorePlot-CocoaTouch.h" 3 4// 折れ線グラフ用のデータソース(CPTPlotDataSource)を記載。CPTScatterPlotDataSourceと間違えないように注意 5@interface ScatterPlotViewController : UIViewController 6<CPTPlotDataSource> 7{ 8@private 9 // グラフ表示領域(この領域に円グラフを追加する) 10 CPTGraph *graph; 11} 12 13// 円グラフで表示するデータを保持する配列 14@property (readwrite, nonatomic) NSMutableArray *scatterPlotData; 15 16@end
こちらが.mのソースコードです
Objective
1#import "ScatterPlotViewController.h" 2 3// 折れ線グラフの識別子 4NSString *const kData = @"Data Source Plot"; 5 6@interface ScatterPlotViewController () 7 8@end 9 10@implementation ScatterPlotViewController 11 12- (void)viewDidLoad 13{ 14 [super viewDidLoad]; 15 16 // グラフに表示するデータを生成 17 // X軸とY軸の両方を設定する必要がある。キーを設定し、次のようなデータ構造になっている 18 // [{ x = 0; y = 0; }, { x = 1; y = 1; }, { x = 2; y = 7; }, 19 // { x = 3; y = 4; }, { x = 4; y = 5; }, { x = 5; y = 2; }, 20 // { x = 6; y = 0; }, { x = 7; y = 6; }, { x = 8; y = 6; }, 21 // { x = 9; y = 9; }, { x = 10: y = 3 }] 22 self.scatterPlotData = [NSMutableArray array]; 23 24 for ( NSUInteger i = 0; i < 11; i++ ) { 25 NSNumber *x = [NSNumber numberWithDouble:i]; 26 NSNumber *y = [NSNumber numberWithDouble:(int)(rand() / (double)RAND_MAX * 10)]; // 1〜10の値のランダム値(int) 27 [self.scatterPlotData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]]; 28 } 29 30 // ホスティングビューを生成 31 CPTGraphHostingView *hostingView = 32 [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)]; 33 // 画面にホスティングビューを追加 34 [self.view addSubview:hostingView]; 35 36 // グラフを生成 37 graph = [[CPTXYGraph alloc] initWithFrame:hostingView.bounds]; 38 hostingView.hostedGraph = graph; 39 40 // グラフのボーダー設定 41 graph.plotAreaFrame.borderLineStyle = nil; 42 graph.plotAreaFrame.cornerRadius = 0.0f; 43 graph.plotAreaFrame.masksToBorder = NO; 44 45 // パディング 46 graph.paddingLeft = 0.0f; 47 graph.paddingRight = 0.0f; 48 graph.paddingTop = 0.0f; 49 graph.paddingBottom = 0.0f; 50 51 graph.plotAreaFrame.paddingLeft = 60.0f; 52 graph.plotAreaFrame.paddingTop = 60.0f; 53 graph.plotAreaFrame.paddingRight = 20.0f; 54 graph.plotAreaFrame.paddingBottom = 65.0f; 55 56 //プロット間隔の設定 57 CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 58 //Y軸は0〜10の値で設定 59 plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(10)]; //←ここのCPTDecimalFromIntの部分 60 //X軸は0〜10の値で設定 61 plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(10)];//←ここのCPTDecimalFromIntの部分 62
こちらは某サイトのサンプルソースコードを参考にしているんですが、軸の設定するコードのところに
CPTDecimalFromInt
のところに
Sending 'NSDecimal' to parameter of incompatible type 'NSNumber *_Nonnull'
とエラーが表示されています。
参考しているサイトを見ると『scatterplot』というのをカスタマイズさせると書かれているのですがその記事がなく、ウェブで検索してもHITされませんでした。
よろしくお願いします。
下記に参考にしているサイトを載せます。
折れ線グラフ
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。