问题
I have a graph, and I want to add two blue axes to this graph, in addition to x-axis and y-axis. However, these blue axes appear under the plot. Any idea how to bring the blue axes on top of the plot? Thank you in advance.
blueAxisList = [[NSMutableDictionary alloc] init];
CPTXYAxis *blueAxis = [blueAxisList objectForKey:name];
blueAxis = [[CPTXYAxis alloc] init];
blueAxis.coordinate = CPTCoordinateX;
blueAxis.plotSpace = plotSpace;
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineWidth = 3.f;
blueAxis.axisLineStyle = lineStyle;
blueAxis.minorTickLineStyle = nil;
blueAxis.majorTickLineStyle = nil;
blueAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
// Line cap on lhs
CPTLineCap *lineCap = [CPTLineCap lineCap];
lineCap.size = CGSizeMake(8., 60.);
lineCap.lineStyle = lineStyle;
lineCap.lineCapType = CPTLineCapTypeRectangle;
const double axisLength = plotSpace.xRange.lengthDouble;
blueAxis.visibleAxisRange = [CPTPlotRange plotRangeWithLocation:plotSpace.xRange.location length:CPTDecimalFromDouble(axisLength)];
blueAxis.axisLineCapMax = lineCap;
NSMutableArray *axesList= [graph.axisSet.axes mutableCopy];
[axesList addObject: blueAxis];
graph.axisSet.axes = axesList;
回答1:
Instead using axes to draw lines across the plot, use additional plots. You can draw both lines with the same plot if they use the same line style. Add the blue plot to the graph after the green one to have it drawn on top.
来源:https://stackoverflow.com/questions/25997224/the-axis-is-drawn-under-the-plot-in-core-plot