2012-07-25 58 views
0

我使用Core-Plot来随时间变化显示温度值。这可以正常工作,但有一个例外:轴没有标题,也没有标记。Core-Plot不显示轴标题

下面你会发现我使用的代码。我正在使用最新版本的CorePlot-CocoaTouch。任何帮助,高度赞赏!提前致谢。

注意:基本上,我遇到了this SO question中所述的相同问题,但是从项目中删除/添加CorePlot并不能解决我的问题。

编辑:我使用了存储库中的最新版本。更改为1.0(下载),它就像一个魅力。

CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero]; 
graphHostingView.collapsesLayers = NO; 
graphHostingView.hostedGraph  = graph; 

graph.paddingLeft = 10.0; 
graph.paddingTop = 10.0; 
graph.paddingRight = 10.0; 
graph.paddingBottom = 10.0; 

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
plotSpace.allowsUserInteraction = YES; 
plotSpace.xRange    = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(500.0)]; 
plotSpace.yRange    = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(40.0)]; 

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;  
CPTXYAxis *x   = axisSet.xAxis; 
x.title = @"Date"; 
x.majorIntervalLength   = CPTDecimalFromString(@"280"); 
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
x.minorTicksPerInterval  = 4;  

CPTXYAxis *y = axisSet.yAxis; 
y.title = @"Temperature"; 
y.majorIntervalLength   = CPTDecimalFromString(@"10"); 
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
y.minorTicksPerInterval  = 2;  

CPTScatterPlot *temperaturePlot = [[CPTScatterPlot alloc] init]; 
temperaturePlot.interpolation = CPTScatterPlotInterpolationCurved; 
temperaturePlot.dataSource = self; 

[graph addPlot:temperaturePlot]; 

编辑:添加填充到plotArea没有帮助,如下面的截图看到。 Plot without padding Plot with padding

回答

0

此问题尚未解决,我将其转发到官方问题列表(core-plot issue)。目前,我切换回版本1.0,正如预期的那样工作。

0

您需要在打印区域框架中添加一些填充以为标签留出空间。

graph.plotAreaFrame.paddingLeft = 70.0; 
graph.plotAreaFrame.paddingTop = 20.0; 
graph.plotAreaFrame.paddingRight = 20.0; 
graph.plotAreaFrame.paddingBottom = 80.0; 
+0

不幸的是,这并没有解决问题。我会在我的问题中附上两张截图。 – tilo 2012-07-26 07:16:27

0

只需尝试添加labelTextStyle属性和一些自定义标签文本样式到您的轴。 axisSet.xAxis.labelTextStyle = LabelStyle; LabelStyle是CPTMutableTextStyle的一个对象。

+0

感谢您的回答,但仍然没有明显的标题(尝试设置颜色,大小,甚至字体)。 – tilo 2012-07-26 07:51:54