Ale*_*exR 1 objective-c uiview core-plot ios
我在散点图中使用了两个 y 轴(y 和 y2),我想将每个轴的标题放置在相同的高度。
请参考我下面的示例图表,其中有两个标题(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;
Run Code Online (Sandbox Code Playgroud)
我需要如何更改我的代码以在两个 y 轴的相同 y 值处绘制标题?
你有什么建议让我的 y 轴标题左对齐,y2 轴右对齐。我目前在 y 轴上使用 titleOffset,但相信可能有更好的方法来做到这一点。
谢谢!

Core-Plot框架中bug修复后的图表:(请参考下面的答案1)

我添加了这个代码片段来展示我如何设置图表和两个散点图(股票价格和估值):
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]];
Run Code Online (Sandbox Code Playgroud)
那是一个 Core Plot 错误,已在此处修复。您现在可以在您的 Core Plot 副本中进行更改。每当发生这种情况时,它将成为下一个版本的一部分。我会写这样的标题代码:
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;
Run Code Online (Sandbox Code Playgroud)
您可以使用绘图空间计算确切的标题位置。例如,要将标题放置在绘图区域上方 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];
Run Code Online (Sandbox Code Playgroud)