我正在使用IOS圖表來繪製水平條形圖,其中有2個y值。我要求在這兩個條形圖上顯示y值,甚至在Y軸(RightAxis)上添加'%'怎麼做 ?這是我的圖形圖像[我繪製的水平條形圖] [1]我使用Objective-C繪製該圖,但使用Swift框架。下面是我使用https://github.com/danielgindi/Charts如何在ios圖表中添加%到Y軸值/標籤?
我加入這個底線我的代碼的鏈接圖表由CREATIV
NSNumberFormatter *formater = [[NSNumberFormatter alloc] init];
formater.numberStyle = NSNumberFormatterPercentStyle;
_graphContainerView.rightAxis.valueFormatter = formater;
如建議但問題是,我得到各條作爲小數點旁邊值如下圖所示的圖像,但我希望他們也以百分比值這裏是我的代碼
- (空)setDataForXAxis:(NSMutableArray的*)xVals benchMarkValues:(NSMutableArray的*)benchMarkVals percentageValues:(NSMutableArray的*)percentVals This image is after adding the below code {
NSMutableArray *yVals1 = [[NSMutableArray alloc] init];
NSMutableArray *yVals2 = [[NSMutableArray alloc] init];
for (int i = 0; i < xVals.count; i++)
{
NSNumber *val = [benchMarkVals objectAtIndex:i];
[yVals1 addObject:[[BarChartDataEntry alloc] initWithValue:val.doubleValue/100 xIndex:i]];
val = [percentVals objectAtIndex:i];
[yVals2 addObject:[[BarChartDataEntry alloc] initWithValue:val.doubleValue/100 xIndex:i]];
}
BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals1 label:@"Sectoral \nBreakdown(Benchmark)"];
[set1 setColor:[UIColor colorWithRed:236/255.f green:205/255.f blue:118/255.f alpha:1.f]];
BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithYVals:yVals2 label:@"Sectoral \nBreakdown(%)"];
[set2 setColor:[UIColor colorWithRed:31/255.f green:125/255.f blue:184/255.f alpha:1.f]];
set2.barSpace = set1.barSpace = 0;
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
[dataSets addObject:set2];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:dataSets];
data.groupSpace = 1.1;
[data setValueFont:[UIFont fontWithName:kUTLightFontName size:6.f]];
_graphContainerView.data = data;
}
謝謝你的工作。但問題是我必須向該條右側顯示的值顯示%值。我使用格式化程序並傳遞這樣的值NSNumberFormatter * formater = [[NSNumberFormatter alloc] init]; formater.numberStyle = NSNumberFormatterPercentStyle; _graphContainerView.rightAxis.valueFormatter = formater; –
先生,我修改了我的問題,並添加了我的結果。所以請讓我知道如何處理這個問題 –
仍然無法測試它,但它應該可能工作,如果你改變DataSet的valueFormatter(在你的情況下set1和set2)。 – creativ