Reputation: 43
how can I draw a vertical line for each date
y-axis works well but why not x-axis?
code for x-axis:
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 2;
majorGridLineStyle.lineColor = [CPTColor redColor];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = [axisSet xAxis];
x.axisLineStyle = nil;
x.majorTickLineStyle = majorGridLineStyle;
[x setLabelingPolicy:CPTAxisLabelingPolicyNone];
x.majorGridLineStyle = majorGridLineStyle;
NSArray *subjectsArray = [self getSubjectTitlesAsArray];
[x setAxisLabels:[NSSet setWithArray:subjectsArray]];
code for y-axis:
CPTXYAxis *y = axisSet.yAxis;
y.axisLineStyle = nil;
y.majorTickLineStyle = nil;
y.minorTickLineStyle = nil;
y.majorIntervalLength = CPTDecimalFromString(@"500");
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
y.majorGridLineStyle = gridLineStyle;
what is my mistake?
Upvotes: 0
Views: 348
Reputation: 43
Thank you Eric !
for sure, there are some more elegant ways to code it, but I solved it like this:
NSMutableSet *xMajorLocations = [NSMutableSet set];
[xMajorLocations addObject:[NSNumber numberWithFloat:0.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:1.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:2.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:3.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:4.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:5.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:6.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:7.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:8.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:9.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:10.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:11.0f]];
[xMajorLocations addObject:[NSNumber numberWithFloat:12.0f]];
x.majorTickLocations = xMajorLocations;
Upvotes: 0
Reputation: 27381
Core Plot will draw grid lines at the major tick locations. Make sure the date values correspond with the tick locations and gridLineStyle
is a style that will appear against the white background.
Upvotes: 1