gpt4 book ai didi

ios - Core Plot 以条形方式截断数据

转载 作者:行者123 更新时间:2023-11-28 22:03:47 26 4
gpt4 key购买 nike

我有一个基于核心图的条形图,我的所有标签都适合,勉强但它们确实适合,但我无法获得上个月(6 月)的相应数据不分成两半。

我试过调整正确的边界,但没有任何效果,有什么想法吗?

我的格式:

    graph                               = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
[graph applyTheme:[CPTTheme themeNamed:kCPTStocksTheme]];
self.hostedGraph = graph;
graph.plotAreaFrame.masksToBorder = NO;
graph.paddingLeft = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingRight = 0.0f;
graph.paddingBottom = 0.0f;

CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineColor = [CPTColor whiteColor];
borderLineStyle.lineWidth = 2.0f;
graph.plotAreaFrame.borderLineStyle = borderLineStyle;
graph.plotAreaFrame.paddingTop = 10.0;
graph.plotAreaFrame.paddingRight = 20.0;
graph.plotAreaFrame.paddingBottom = 80.0;
graph.plotAreaFrame.paddingLeft = 55.0;

//Add plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
//CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.newPlotSpace;
plotSpace.delegate = self;

//MAX Y

int TOP = [[NSString stringWithFormat:@"%02f", highestPoint] intValue];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(TOP +5)];

//MAX X
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-1)
length:CPTDecimalFromInt(numOfBars)];
#pragma mark - Grid Lines
//Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];
CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];

//Axes
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
#pragma mark - X- Axis
//X axis
CPTXYAxis *x = axisSet.xAxis;
x.orthogonalCoordinateDecimal = CPTDecimalFromInt(0);
x.majorIntervalLength = CPTDecimalFromInt(1);
x.minorTicksPerInterval = 0;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.majorGridLineStyle = majorGridLineStyle;
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];

//X labels
int labelLocations = 0;
NSMutableArray *customXLabels = [NSMutableArray array];
#pragma mark - X- Axis Labels
for (NSString *day in xAxis) {
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:day textStyle:x.labelTextStyle];
newLabel.tickLocation = [[NSNumber numberWithInt:labelLocations] decimalValue];
newLabel.offset = x.labelOffset + x.majorTickLength;
newLabel.rotation = M_PI / 4;
[customXLabels addObject:newLabel];
labelLocations++;

}
x.axisLabels = [NSSet setWithArray:customXLabels];
NSLog(@"%@", xAxis);

//Y axis
#pragma mark - Y- Axis
CPTXYAxis *y = axisSet.yAxis;
//y.title = @"Profit";
//y.titleOffset = 40.0f;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;

//THIS WAS 0
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];

//Create a bar line style
CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineWidth = 1.0;
barLineStyle.lineColor = [CPTColor whiteColor];
CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];
whiteTextStyle.color = [CPTColor whiteColor];

//Plot
BOOL firstPlot = YES;
for (NSString *set in [[sets allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]) {
CPTBarPlot *plot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
plot.lineStyle = barLineStyle;
CGColorRef color = ((UIColor *)[sets objectForKey:set]).CGColor;
plot.fill = [CPTFill fillWithColor:[CPTColor colorWithCGColor:color]];
if (firstPlot) {
plot.barBasesVary = NO;
firstPlot = NO;
} else {
plot.barBasesVary = YES;
}
plot.barWidth = CPTDecimalFromFloat(0.8f);
plot.barsAreHorizontal = NO;
plot.dataSource = self;
plot.identifier = set;
[graph addPlot:plot toPlotSpace:plotSpace];
}
}

也不太重要,但我如何去除黑角?

Core Plot Cut off

最佳答案

条形以 x 位置为中心,这就是为什么您只能看到最后一个条形的一半。增加 xRange 的长度以为栏的另一半腾出空间。将其增加 0.5 以使条形末端靠近绘图区域的边缘或 1.0 以与第一个条形对称。

关于ios - Core Plot 以条形方式截断数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24478979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com