17
A
回答
35
不幸的是,由於框架的API尚未穩定,所以沒有那麼多的教程,其中一些已經存在的教程已經過時。示例應用程序確實是瞭解如何使用框架的最佳資源。
例如,要提供自定義軸標籤,請查看CPTestApp-iPhone的CPTestAppBarChartController.m
源文件。在這個例子柱形圖通過下面的代碼定義的自定義X軸標籤:
// Define some custom labels for the data elements
x.labelRotation = M_PI/4;
x.labelingPolicy = CPAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
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 = x.labelOffset + x.majorTickLength;
newLabel.rotation = M_PI/4;
[customLabels addObject:newLabel];
[newLabel release];
}
x.axisLabels = [NSSet setWithArray:customLabels];
首先,設置軸標籤政策CPAxisLabelingPolicyNone
讓框架知道你會提供自定義標籤,然後創建一個最後您將該標籤數組分配給X軸上的axisLabels
屬性。
0
要提供自定義格式化標籤,您可以將一個格式化程序分配給軸的labelFormatter屬性。您可以使用配置您的喜好NSNumberFormatter,例如:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
// ... configure formatter
CPTXYAxis *y = axisSet.yAxis;
y.labelFormatter = formatter;
或者,如果你需要更具體的格式,你可以繼承NSNumberFormatter
並重寫stringForObjectValue:
方法做你想確切的格式。
相關問題
- 1. 核心圖x軸標籤未顯示
- 2. 核心圖:使用自定義軸標籤交替填充軸
- 3. 核心繪圖軸標籤在繪圖區域外不可見
- 4. 核心圖,標籤長度
- 5. 核心情節1.0:提供自定義標籤的傳奇
- 6. php5 +提供的核心類列表?
- 7. 核心圖x軸標籤不可見 - 邊界rects?
- 8. 在覈心圖中動態更改Y軸標籤和線
- 9. 算法將軸標籤設置爲核心圖中5或10的倍數
- 10. 如何爲核心繪圖數據標籤添加動畫?
- 11. rails:如何爲提交標籤提供圖片?
- 12. 如何隱藏圖表軸標籤
- 13. 核心繪圖圖形標籤步驟
- 14. xamarin核心圖y軸值
- 15. 如何消除軸後,中心的R繪圖標籤
- 16. WPF DVC圖表軸標籤
- 17. vtk圖表 - 如何在軸線的末端繪製軸標籤?
- 18. 如何從核心繪圖軸標籤數組中獲取xAxis標籤文本值?
- 19. 核心繪圖標籤沒有顯示
- 20. Windows窗體C#圖表軸標籤軸
- 21. 核心陰謀,如何改變消極軸刻度標籤的顏色
- 22. 座標軸繪製在覈心圖中的圖下
- 23. 在extjs圖表中,如何隱藏軸和軸標籤?
- 24. 如何強制圖表X軸標籤間隔爲100? (C#,.NET)
- 25. 無法在覈心圖中的x軸和y軸標籤上顯示任何內容
- 26. 如何使用自定義標籤在覈心圖上打勾?
- 27. 如何強制核心圖庫不能本地化標籤?
- 28. 核心繪圖x軸標籤重疊/ CPTLabellingPolicyAutomatic不會顯示日期
- 29. 如何爲d3圖表提取標稱標籤
- 30. OBJ-C:核心繪圖XY軸固定
我們如何爲餅圖中的每個切片添加標籤?謝謝 – Pooja 2011-05-18 14:42:44
customTickLocations包含5,10 ...它與x軸範圍有關嗎?因爲我有幾秒鐘的x軸包含值,那麼在我的情況下customTickLocations中的值是什麼..謝謝 – Pooja 2011-06-16 15:57:55
@Pooja自定義標籤可以以與答案完全相同的方式添加到餅圖中...您是歡迎。你可以在[這個SO答案]中提到的自定義勾號位置工作(http://stackoverflow.com/questions/3208025/core-plot-still-do-not-understand-how-to-have-custom-label-和 - 滴答聲)...不客氣! – tipycalFlow 2012-03-19 10:59:53