The spaceBetweenXAxisTicks
should be the length of the plot space xRange
divided by the number of tick marks minus one (1).
Core plot: Make x-axis ticks evenly spaced
-
15-10-2022 - |
Question
I have a core plot graph in which I have prices data. The x-axis represents the time, while the y represents the price. I've determined that it's this code specifically that determines the space in between the tick marks:
CGFloat dateCount = [timestamps count];
NSMutableSet *xLabels = [NSMutableSet setWithCapacity:dateCount];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:dateCount];
float i = 0;
for (NSString *date in timestampStrings) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:date textStyle:x.labelTextStyle];
CGFloat location = i+=spaceBetweenXAxisTicks; // Here's where the space between is set
label.tickLocation = CPTDecimalFromCGFloat(location);
label.offset = x.majorTickLength;
if (label) {
[xLabels addObject:label];
[xLocations addObject:[NSNumber numberWithFloat:location]];
}
}
Is there some way to dynamically set the space in between so the last tick hits the right of the graph? Thanks!
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow