1

散布図で 2 つの y 軸 (y と y2) を使用しており、各軸のタイトルを同じ高さに配置したいと考えています。

以下のサンプル チャートを参照してください。2 つのタイトル (y: "USD" と y2: "ev/ebit") があります。残念ながら、両方のタイトルをまったく同じ高さ (y 値) で描画する方法が見つかりませんでした。

これは、現在、タイトルの y 位置を計算する方法です。

double yTitleLocation = plotSpace.yRange.lengthDouble + plotSpace.yRange.locationDouble;
yAxis.titleLocation = CPTDecimalFromDouble(yTitleLocation);
yAxis.title = self.issue.company.contrCurrency;
yAxis.titleRotation = 2 * M_PI;
yAxis.titleOffset = -15;

double y2TitleLocation = valuationPlotSpace.yRange.lengthDouble + valuationPlotSpace.yRange.locationDouble;
y2Axis.titleLocation = CPTDecimalFromDouble(y2TitleLocation);
y2Axis.title = self.valuation.id;
y2Axis.titleRotation = 2 * M_PI;

両方の y 軸の同じ​​ y 値でタイトルを描画するには、コードをどのように変更する必要がありますか?

y 軸のタイトルを左揃えにし、y2 軸の右揃えにする方法を教えてください。現在、y 軸に titleOffset を使用していますが、これを行うためのより良い方法があると考えています。

ありがとうございました! 軸のタイトル

Core-Plot フレームワークのバグ修正後のチャート: (以下の回答 1 を参照してください)

ここに画像の説明を入力

編集:これは私がチャートを設定する方法です:

グラフと 2 つの散布図 (株価と評価) の設定方法を示すために、このコード スニペットを追加しました。

graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
self.hostView.hostedGraph = graph;
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];    
graph.frame = self.view.bounds;
graph.plotAreaFrame.masksToBorder = NO;
graph.plotAreaFrame.cornerRadius  = 0.0f;

CPTScatterPlot *sharePricePlot = [[CPTScatterPlot alloc] initWithFrame:graph.bounds];
sharePricePlot.identifier = @"CloseSharePricePlot";
sharePricePlot.dataLineStyle = sharePricePlotLineStyle;
sharePricePlot.dataSource = self;

CPTScatterPlot *valuationPlot = [[CPTScatterPlot alloc]initWithFrame:graph.bounds];
valuationPlot.dataSource = self;

CPTXYPlotSpace *valuationPlotSpace = [[CPTXYPlotSpace alloc] init];
valuationPlotSpace.identifier = ValuationPlotSpaceIdentifier;
[graph addPlotSpace:valuationPlotSpace];

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
     
[plotSpace scaleToFitPlots:[NSArray arrayWithObject:sharePricePlot]];
[valuationPlotSpace scaleToFitPlots:[NSArray arrayWithObject:valuationPlot]];
4

1 に答える 1

5

これはコアプロットのバグであり、ここで修正されました。今のところ、CorePlotのコピーでその変更を行うことができます。それが起こるときはいつでも、それは次のリリースの一部になるでしょう。タイトルコードは次のように記述します。

yAxis.titleLocation = plotSpace.yRange.maxLimit;
yAxis.title = self.issue.company.contrCurrency;
yAxis.titleRotation = 0.0;
yAxis.titleOffset = -15;

y2Axis.titleLocation = valuationPlotSpace.yRange.maxLimit;
y2Axis.title = self.valuation.id;
y2Axis.titleRotation = 0.0;
y2Axis.titleOffset = -15;

プロットスペースを使用して、正確なタイトルの場所を計算できます。たとえば、タイトルをプロット領域の15ピクセル上に配置するには、次のようにします。

CGRect plotAreaBounds = graph.plotAreaFrame.plotArea.bounds;
CGPoint viewPoint = CGPointMake(CGRectMinX(plotAreaBounds), 
                                CGRectMaxY(plotAreaBounds) + 15.0);

NSDecimal plotPoint[2];
[plotSpace plotPoint:plotPoint forPlotAreaViewPoint:viewPoint];

yAxis.titleLocation = plotPoint[CPTCoordinateY];
于 2012-08-12T14:09:54.583 に答える