いつもありがとうございます。また回答の方お願いします。
今現在coreplotで対数スケールのグラフを表示させているのですがx軸が見えている枠内に収めて等間隔にしたいんですけど、どのようにしたらいいでしょうか。
アドバイスお願いします。
objective
1// ホスティングビューを生成 2 CPTGraphHostingView *hostingView = 3 [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)]; 4 // 画面にホスティングビューを追加 5 [self.view addSubview:hostingView]; 6 7 // グラフを生成 8 graph = [[CPTXYGraph alloc] initWithFrame:hostingView.bounds]; 9 hostingView.hostedGraph = graph; 10 11 // グラフのボーダー設定 12 graph.plotAreaFrame.borderLineStyle = nil; 13 graph.plotAreaFrame.cornerRadius = 0.0f; 14 graph.plotAreaFrame.masksToBorder = NO; 15 16 // パディング 17 graph.paddingLeft = 0.0f; 18 graph.paddingRight = 0.0f; 19 graph.paddingTop = 0.0f; 20 graph.paddingBottom = 0.0f; 21 22 graph.plotAreaFrame.paddingLeft = 60.0f; 23 graph.plotAreaFrame.paddingTop = 60.0f; 24 graph.plotAreaFrame.paddingRight = 20.0f; 25 graph.plotAreaFrame.paddingBottom = 65.0f; 26 27 //プロット間隔の設定 28 CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 29 //CPTScaleTypeLogは対数.CPTScaleTypeLinearは通常 30 plotSpace.xScaleType = CPTScaleTypeLog; 31 plotSpace.yScaleType = CPTScaleTypeLog; 32 plotSpace.allowsUserInteraction = NO; 33 //軸の位置と軸の長さ 小数点のためfloat 34 plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0001f) 35 length:CPTDecimalFromInt(10000)]; 36 plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0001f) 37 length:CPTDecimalFromInt(1.0f)]; 38 39 40 // テキストスタイル 41 CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle]; 42 textStyle.color = [CPTColor colorWithComponentRed:0.447f green:0.443f blue:0.443f alpha:1.0f]; 43 textStyle.fontSize = 13.0f; 44 textStyle.textAlignment = CPTTextAlignmentCenter; 45 46 // ラインスタイル 47 CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle]; 48 lineStyle.lineColor = [CPTColor colorWithComponentRed:0.788f green:0.792f blue:0.792f alpha:1.0f]; 49 lineStyle.lineWidth = 2.0f; 50 51 //labelformatから小数点以下を省く 52 NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 53 [formatter setMaximumFractionDigits:0]; 54 55 56 57 58 59 60 // X軸のメモリ・ラベルなどの設定 61 CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 62 CPTXYAxis *x = axisSet.xAxis; 63 x.axisLineStyle = lineStyle; // X軸の線にラインスタイルを適用 64 x.majorTickLineStyle = lineStyle; // X軸の大きいメモリにラインスタイルを適用 65 x.minorTickLineStyle = nil; // X軸の小さいメモリにラインスタイルを適用 66 x.minorTicksPerInterval = 0; // 小さいメモリの数 67 x.majorIntervalLength = CPTDecimalFromString(@"3333.3333");// X軸ラベルの表示間隔 68 69 x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); // X軸のY位置 70 x.title = @""; 71 x.titleTextStyle = textStyle; 72 x.titleLocation = CPTDecimalFromFloat(40.0f);// タイトルの位置設定 73 x.titleOffset = 36.0f; 74 x.labelFormatter = formatter; 75 76 77 //x.minorTickLength = 5.0f; // X軸のメモリの長さ 78 //x.majorTickLength = 9.0f; // X軸のメモリの長さ ラベルを設定しているため無効ぽい 79 x.labelTextStyle = textStyle; 80 81 82 83 84 85 86 87 88 89 90 // Y軸のメモリ・ラベルなどの設定 91 CPTXYAxis *y = axisSet.yAxis; 92 y.axisLineStyle = lineStyle; // Y軸の線にラインスタイルを適用 93 y.majorTickLineStyle = lineStyle; // Y軸の大きいメモリにラインスタイルを適用 94 y.minorTickLineStyle = lineStyle; // Y軸の小さいメモリにラインスタイルを適用 95 y.majorTickLength = 5.0f; // Y軸の大きいメモリの長さ 96 y.minorTickLength = 0.0f; // Y軸の小さいメモリの長さ 97 y.majorIntervalLength = CPTDecimalFromFloat(0.1f); // Y軸ラベルの表示間隔 98 y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0.0f); // Y軸のX位置 99 y.title = @""; 100 y.titleTextStyle = textStyle; 101 y.titleRotation = M_PI*2; 102 y.titleLocation = CPTDecimalFromFloat(8.0f); // タイトルの位置設定 103 lineStyle.lineWidth = 0.0001f; //y軸表示の線の大きさ 104 y.titleOffset = 0.0f; 105 y.majorGridLineStyle = lineStyle; 106 //y.labelTextStyle = textStyle; 107 108 109 110 // 折れ線グラフのインスタンスを生成 111 CPTScatterPlot *scatterPlot = [[CPTScatterPlot alloc] init]; 112 scatterPlot.identifier = kData; // 折れ線グラフを識別するために識別子を設定 113 scatterPlot.dataSource = self; // 折れ線グラフのデータソースを設定 114 115 // 折れ線グラフのスタイルを設定 116 CPTMutableLineStyle *graphlineStyle = [scatterPlot.dataLineStyle mutableCopy]; 117 graphlineStyle.lineWidth = 3; // 太さ 118 graphlineStyle.lineColor = [CPTColor colorWithComponentRed:0.823f green:0.82f blue:0.831f alpha:0.50f];// 色 119 120 scatterPlot.dataLineStyle = graphlineStyle; 121 122 // グラフに折れ線グラフを追加 123 [graph addPlot:scatterPlot]; 124
あなたの回答
tips
プレビュー