0
votes

I'm using Core-Plot to visualize temperature values over time. This works fine with one exception: no titles are shown for the axes, nor are ticks labeled.

Below you will find the code I'm using. I'm using the latest version of CorePlot-CocoaTouch. Any help is highly appreciated! Thanks in advance.

Note: Basically, I'm having the same problem stated in this SO question, but removing/adding CorePlot from/to the project doesn't solve my problem.

Edit: I used the latest version from the repository. Changing to 1.0 (the download), it works like a charm.

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];

Edit: Adding padding to the plotArea does not help, as seen in the screenshots below. Plot without paddingPlot with padding

3

3 Answers

0
votes

You need to add some padding to the plot area frame to make room for the labels.

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

Just try by adding labelTextStyle property with some custom label Text style to your axis. axisSet.xAxis.labelTextStyle = LabelStyle; LabelStyle is an object of CPTMutableTextStyle.

0
votes

This issue isn't solved yet and I forwarded it to the official issue list (core-plot issue). For the moment, I switched back to version 1.0 which is working as expected.