1
我第一次使用CorePlot,現在想自定義條形圖。你在這張照片中看到它。條形圖上的自定義標籤(CorePlot框架)
我想現在在每欄上的酒吧
頂部添加號碼希望你知道我的意思。
我該如何認識它?
這是我的代碼
-(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