2014-12-03 153 views
0

当我设置hostingView.collapsesLayers = NO时,我的图形的轴线和刻度线不出现。当我设置hostingView.collapsesLayers = YES时,它们确实出现。任何想法可能会导致这种情况?未显示核心绘图轴线

我试着改变图层顺序,但没有顺序(我试过)似乎使轴线出现。这个问题似乎也没有与托管视图的背景颜色或图形的填充颜色有关,我试图将它们设置为两者都清晰。

轴标签出现在正确的位置。

编辑:网格线和注释也都出现了。除了轴线和刻度线以外,所有内容都应该显示。

EDIT2:图形安装程序代码,称为viewDidAppear

//create graph and hosting view 
_graph = [[CPTXYGraph alloc] initWithFrame:_graphHostingView.frame]; 
_graphHostingView.hostedGraph = _graph; 
_graphHostingView.collapsesLayers = NO; 

//format graph 
CGFloat graphPadding = 0.0f; 
_graph.paddingBottom = graphPadding; 
_graph.paddingLeft = graphPadding; 
_graph.paddingRight = graphPadding; 
_graph.paddingTop = graphPadding; 
_graph.fill = [CPTFill fillWithColor:[CPTColor whiteColor]]; 
CGFloat plotPadding = 20.0f; 
_graph.plotAreaFrame.paddingBottom = plotPadding; 
_graph.plotAreaFrame.paddingLeft = plotPadding; 
_graph.plotAreaFrame.paddingRight = plotPadding; 
_graph.plotAreaFrame.paddingTop = plotPadding; 

//configure plot spaces 
_rightAxisPlotSpace = [[CPTXYPlotSpace alloc] init]; 
[_graph addPlotSpace:_rightAxisPlotSpace]; 

//init axes 
_xAxis = [[CPTXYAxis alloc] init]; 
_xAxis.coordinate = CPTCoordinateX; 
_xAxis.plotSpace = _graph.defaultPlotSpace; 
_yAxisLeft = [[CPTXYAxis alloc] init]; 
_yAxisLeft.coordinate = CPTCoordinateY; 
_yAxisLeft.plotSpace = _graph.defaultPlotSpace; 
_yAxisRight = [[CPTXYAxis alloc] init]; 
_yAxisRight.coordinate = CPTCoordinateY; 
_yAxisRight.plotSpace = _rightAxisPlotSpace; 
_xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0f]; 
_yAxisLeft.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0f]; 
_yAxisRight.axisConstraints = [CPTConstraints constraintWithUpperOffset:0.0f]; 
_xAxis.tickDirection = CPTSignNegative; 
_yAxisLeft.tickDirection = CPTSignNegative; 
_yAxisRight.tickDirection = CPTSignPositive; 

CPTAxisSet* axisSet = [[CPTAxisSet alloc] init]; 
axisSet.axes = [NSArray arrayWithObjects:_xAxis, _yAxisLeft, _yAxisRight, nil]; 
_graph.axisSet = axisSet; 

//format axes 
CPTMutableLineStyle* axisStyle = [CPTMutableLineStyle lineStyle]; 
axisStyle.lineWidth = 0.75f; 
axisStyle.lineColor = [CPTColor colorWithCGColor:DARK_GRAY.CGColor]; 
CPTMutableLineStyle* axisTickStyle = [CPTMutableLineStyle lineStyle]; 
axisTickStyle.lineWidth = 0.5f; 
axisTickStyle.lineColor = axisStyle.lineColor; 
CPTMutableLineStyle* gridStyle = [CPTMutableLineStyle lineStyle]; 
gridStyle.lineWidth = 0.25f; 
gridStyle.lineColor = [CPTColor colorWithCGColor:LIGHT_GRAY.CGColor]; 
CPTMutableTextStyle* labelTextStyle = [CPTMutableTextStyle textStyle]; 
labelTextStyle.fontName = FONT_REGULAR; 
labelTextStyle.fontSize = 8.0f; 
labelTextStyle.color = [CPTColor colorWithCGColor:DARK_GRAY.CGColor]; 
CPTMutableTextStyle* leftAxisTitleStyle = [CPTMutableTextStyle textStyle]; 
leftAxisTitleStyle.fontName = FONT_HEAVY; 
leftAxisTitleStyle.fontSize = 10.0f; 
leftAxisTitleStyle.color = [CPTColor colorWithCGColor:BLUE.CGColor]; 
CPTMutableTextStyle* rightAxisTitleStyle = [CPTMutableTextStyle textStyle]; 
rightAxisTitleStyle.fontName = FONT_HEAVY; 
rightAxisTitleStyle.fontSize = 10.0f; 
rightAxisTitleStyle.color = [CPTColor colorWithCGColor:YELLOW.CGColor]; 
CPTTimeFormatter* calendarFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:_dateFormatter]; 
_xAxis.majorGridLineStyle = gridStyle; 
_xAxis.labelFormatter = calendarFormatter; 

NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init]; 
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; 
[numberFormatter setMinimumFractionDigits:0]; 
[numberFormatter setMaximumFractionDigits:2]; 
_yAxisLeft.majorGridLineStyle = gridStyle; 
_yAxisLeft.minorGridLineStyle = gridStyle; 
_yAxisLeft.titleTextStyle = leftAxisTitleStyle; 
_yAxisLeft.titleOffset = 20.0f; 
_yAxisLeft.labelFormatter = numberFormatter; 

_yAxisRight.majorGridLineStyle = nil; 
_yAxisRight.minorGridLineStyle = nil; 
_yAxisRight.titleTextStyle = rightAxisTitleStyle; 
_yAxisRight.titleOffset = 20.0f; 
_yAxisRight.titleRotation = 3.0f*M_PI/2.0f; 
_yAxisRight.labelFormatter = numberFormatter; 
for(CPTXYAxis* axis in _graph.axisSet.axes) 
{ 
    axis.labelingPolicy = CPTAxisLabelingPolicyAutomatic; 
    axis.preferredNumberOfMajorTicks = 7; 
    axis.minorTicksPerInterval = 0; 
    axis.majorTickLineStyle = axisTickStyle; 
    axis.minorTickLineStyle = axisTickStyle; 
    axis.axisLineStyle = axisStyle; 
    axis.labelTextStyle = labelTextStyle; 
    axis.majorTickLength = 3.0f; 
    axis.minorTickLength = 1.5f; 
    axis.labelOffset = 0.0f; 
} 

//set chart layer order 
NSArray* chartLayers = [NSArray arrayWithObjects:[NSNumber numberWithInteger:CPTGraphLayerTypeAxisLines], 
         [NSNumber numberWithInteger:CPTGraphLayerTypeAxisLabels], 
         [NSNumber numberWithInteger:CPTGraphLayerTypePlots], 
         [NSNumber numberWithInteger:CPTGraphLayerTypeMajorGridLines], 
         [NSNumber numberWithInteger:CPTGraphLayerTypeMinorGridLines], 
         [NSNumber numberWithInteger:CPTGraphLayerTypeAxisTitles], nil]; 
_graph.topDownLayerOrder = chartLayers; 
+0

请张贴您的图表设置代码。 – 2014-12-04 01:33:21

+0

编辑包含图表设置代码@EricSkroch – mistershoe 2014-12-04 17:18:11

回答

0

而不是替换默认轴设置,只要将新的轴阵列它:

_graph.axisSet.axes = @[_xAxis, _yAxisLeft, _yAxisRight]; 

要更换CPTXYAxisSet与不知道如何布局和绘制xy轴的CPTAxisSet

+0

谢谢!有效。 – mistershoe 2014-12-05 03:13:59