大家好,有人可以帮我解决我遇到的这个问题吗
我可以在 coreplote 中绘制一个条形图宽度不等的条形图吗假设我的 X 轴间隔是 1 个单位,并且我已将条形图宽度设置为相同的 1 个单位。但是在某些点 x 轴值以 0.5 个单位变化,我希望条形宽度等于发生变化的宽度。而且数据是动态变化的。有没有其他我可以使用的解决方案,并且看起来仍然像条形图。使用 bar 的唯一原因是我需要填充绘图空间。
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)barChart.defaultPlotSpace;
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromInt(0)
length:CPDecimalFromInt(rangeY)];
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-0.5f)
length:CPDecimalFromFloat(rangeX)];
CPXYAxisSet *axisSet = (CPXYAxisSet *)barChart.axisSet;
CPXYAxis *x = axisSet.xAxis;
x.axisLineStyle = nil;
x.majorTickLineStyle = nil;
x.minorTickLineStyle = nil;
x.majorIntervalLength = CPDecimalFromString(@"1");
x.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
x.title = [[[tempCol colName] componentsSeparatedByString:@"*@"] objectAtIndex:0];
x.titleLocation = CPDecimalFromFloat((rangeX-1)/2);
x.titleOffset = 25.0f;
// Define some custom labels for the data elements
x.labelRotation = 0;
x.labelingPolicy = CPAxisLabelingPolicyNone;
NSMutableArray *customTickLocations = [[NSMutableArray alloc] init];
NSMutableArray *xAxisLabels = [[NSMutableArray alloc] init];
for (int i = 0; i < [tempGraph.d2pArray count]; i++) {
tempD2P = [tempGraph.d2pArray objectAtIndex:i];
[customTickLocations addObject:[NSNumber numberWithInt:i]];
[xAxisLabels addObject:[tempD2P d2pName]];
}
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations) {
CPAxisLabel *newLabel = [[CPAxisLabel alloc]
initWithText:[xAxisLabels objectAtIndex:labelLocation++]
textStyle:x.labelTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
newLabel.offset = 0;
newLabel.rotation = 0;
newLabel.alignment = CPAlignmentCenter;
[customLabels addObject:newLabel];
[newLabel release];
newLabel = nil;
}
[xAxisLabels release];
xAxisLabels = nil;
[customTickLocations release];
customTickLocations = nil;
x.axisLabels = [NSSet setWithArray:customLabels];
CPXYAxis *y = axisSet.yAxis;
CPLineStyle *majorGridLineStyle = [CPLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.lineColor = [CPColor colorWithCGColor:[[UIColor grayColor] CGColor]];
y.axisLineStyle = nil;
y.majorTickLineStyle = nil;
y.majorGridLineStyle = majorGridLineStyle;
y.minorTickLineStyle = nil;
y.majorIntervalLength = CPDecimalFromInt(rangeY/8);
y.orthogonalCoordinateDecimal = CPDecimalFromString(@"-0.5");
y.title = [[[tempCol colName] componentsSeparatedByString:@"*@"] objectAtIndex:1];
y.titleOffset = 30 + 5*log10(mult);
y.titleLocation = CPDecimalFromInt(rangeY/2);
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:0];
y.labelFormatter = formatter;
[formatter release];
formatter = nil;
char firstChar = 'F';
CPBarPlot *barPlot;
// First bar plot
for (int i = 0; i < noOfBarCharts; i++) {
static CPTextStyle *whiteText = nil;
if ( !whiteText ) {
whiteText = [[CPTextStyle alloc] init];
whiteText.color = [CPColor whiteColor];
whiteText.fontSize = 14;
}
barPlot = [CPBarPlot tubularBarPlotWithColor:[CPColor colorWithComponentRed:[[[rgbArray objectAtIndex:0] objectAtIndex:i] floatValue]/255.0
green:[[[rgbArray objectAtIndex:1] objectAtIndex:i] floatValue]/255.0
blue:[[[rgbArray objectAtIndex:2] objectAtIndex:i] floatValue]/255.0
alpha:1.0]
horizontalBars:NO];
barPlot.baseValue = CPDecimalFromString(@"0");
barPlot.dataSource = self;
barPlot.barOffset = ([tempGraph.graType rangeOfString:@"GROUPED"].location != NSNotFound)?(i+0.5)-(noOfBarCharts/2):0;
barPlot.labelOffset = 0;
barPlot.barWidth = 20;
barPlot.identifier = [NSString stringWithFormat:@"%d%c", [tempGraph.graID intValue], (firstChar - noOfBarCharts +1 + i)];
barPlot.delegate = self;
[barChart addPlot:barPlot
toPlotSpace:plotSpace];