0

我正在使用 Core-Plot 来可视化一段时间内的温度值。除了一个例外,这很好用:没有显示轴的标题,也没有标记刻度。

您将在下面找到我正在使用的代码。我正在使用最新版本的 CorePlot-CocoaTouch。非常感谢任何帮助!提前致谢。

注意:基本上,我遇到了这个 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 添加填充没有帮助,如下面的屏幕截图所示。 没有填充的绘图 带填充的绘图

4

3 回答 3

0

您需要在绘图区域框架中添加一些填充以为标签腾出空间。

graph.plotAreaFrame.paddingLeft   = 70.0;
graph.plotAreaFrame.paddingTop    = 20.0;
graph.plotAreaFrame.paddingRight  = 20.0;
graph.plotAreaFrame.paddingBottom = 80.0;
于 2012-07-26T00:02:57.163 回答
0

这个问题还没有解决,我把它转发到了官方问题列表(core-plot issue)。目前,我切换回 1.0 版,它按预期工作。

于 2012-09-18T11:34:36.157 回答
0

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

于 2012-07-26T07:28:20.140 回答