1
저는 CorePlot을 처음 사용했으며 이제 막대 그래프를 사용자 지정하려고합니다. 당신은이 그림에서 그것을 봅니다.막대 그래프 (CorePlot Framework)에 대한 사용자 지정 레이블
는 지금 바
의 상단에있는 모든 줄을 통해 번호를 추가 할 희망 당신은 내가 무슨 뜻인지 알아.
어떻게 알 수 있습니까? 당신은 단순한 숫자 레이블, 플롯에 labelTextStyle
및 labelFormatter
속성을 설정하려면
이 내 코드
-(void) generateDataSamples
{
int rawSamples [] = {1,3,6,2,1,1,3,15,2,1};
int numSamples = sizeof(rawSamples)/sizeof(int);
samples = [[NSMutableArray alloc] initWithCapacity:numSamples];
for (int i = 0; i < numSamples; i++){
double x = i;
double y = rawSamples[i];
NSDictionary *sample = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:x],X_VAL,
[NSNumber numberWithDouble:y],Y_VAL,
nil];
[samples addObject:sample];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self generateDataSamples];
double xAxisStart = 0;
double xAxisLength = [samples count];
double yAxisStart = 0;
double yAxisLength = [[samples valueForKeyPath:@"@max.Y_VAL"] doubleValue];
CPGraphHostingView *hostingView = [[CPGraphHostingView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:hostingView];
CPXYGraph *graph = [[CPXYGraph alloc] initWithFrame:self.view.bounds];
hostingView.hostedGraph = graph;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0)
length:CPDecimalFromDouble(xAxisLength +1)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0)
length:CPDecimalFromDouble(yAxisLength + 0.5)];
CPBarPlot *plot = [[CPBarPlot alloc] initWithFrame:CGRectZero];
plot.plotRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0.0)
length:CPDecimalFromDouble(xAxisLength)];
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor whiteColor];
lineStyle.lineWidth = 1.0f;
CPTextStyle *cyanStyle = [CPTextStyle textStyle];
cyanStyle.color = [CPColor cyanColor];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:0];
plot.barOffset = .5;
plot.dataSource = self;
[graph addPlot:plot];
[plot release];
[graph release];
[hostingView release];
}
@TeamNoX가 질문을 해결하는 데 도움이되는 훌륭한 지식과 훌륭한 답변을 제공합니다. 저에게 도움이되는 부분은'dataLabelForPlot'입니다. 고마워 +1. – Jacksonkr