내 프로젝트에 https://github.com/danielgindi/Charts 라이브러리를 사용했습니다.
완벽하게 작동하지만 사용자가 바를 두드렸을 때만 바 데이터를 선택하려고합니다.
현재는 바 외부의 막대 데이터를 반환합니다.
사용자가 막대 바깥을 탭하면 가장 가까운 막대 데이터를 탭에 제공합니다.차트 : 바 내부를 두 드릴 때만 선택된 바 데이터 가져 오기
_chartView.delegate = self;
_chartView.drawBarShadowEnabled = NO;
_chartView.drawValueAboveBarEnabled = YES;
_chartView.maxVisibleValueCount = 60;
ChartXAxis *xAxis = _chartView.xAxis;
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.labelTextColor = [UIColor whiteColor];
xAxis.labelFont = [UIFont systemFontOfSize:20.f];
xAxis.drawGridLinesEnabled = NO;
xAxis.spaceBetweenLabels = 2.0;
xAxis.labelWidth = 100;
ChartYAxis *leftAxis = _chartView.leftAxis;
leftAxis.labelFont = [UIFont systemFontOfSize:20.f];
leftAxis.labelCount = 5;
leftAxis.labelTextColor = [UIColor whiteColor];
leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];
leftAxis.valueFormatter.maximumFractionDigits = 1;
leftAxis.valueFormatter.negativeSuffix = @"k";
leftAxis.valueFormatter.positiveSuffix = @"k";
leftAxis.valueFormatter.positivePrefix = @"$";
leftAxis.valueFormatter.negativePrefix = @"$";
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;
leftAxis.spaceTop = 0.15;
leftAxis.customAxisMin = 0.0; // this replaces startAtZero = YES
_chartView.legend.position = ChartLegendPositionBelowChartLeft;
_chartView.legend.form = ChartLegendFormSquare;
_chartView.legend.formSize = 20.0;
_chartView.legend.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:20.f];
_chartView.legend.xEntrySpace = 4.0;
_chartView.legend.textColor = [UIColor whiteColor];
NSMutableArray *xVals = [[NSMutableArray alloc] init];
for (int i = 0; i < 12; i++)
{
[xVals addObject:months[i % 12]];
}
NSMutableArray *yVals = [[NSMutableArray alloc] init];
NSMutableArray *yValsColor = [[NSMutableArray alloc] init];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:10 xIndex:1]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:15 xIndex:2]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:20 xIndex:3]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:45 xIndex:4]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:30 xIndex:5]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:5 xIndex:6]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:15 xIndex:7]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:22 xIndex:8]];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:32 xIndex:9]];
[yValsColor addObject:[UIColor yellowColor]];
BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals label:@"Charges"];
set1.barSpace = 0.35;
set1.colors = yValsColor;
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:dataSets];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:20.f]];
[data setValueTextColor:[UIColor whiteColor]];
_chartView.data = data;
NSArray *arrLabelData = [NSArray arrayWithObjects:@"All", @"1/1/2016 to 9/29/2016", @"All", @"All", @"Date of Billed",nil];
NSArray *arrLabel = [NSArray arrayWithObjects:@"Ins:",@" DOS:",@" Location:",@" Provider:",@" Aging Calculation Based On:",nil];
NSMutableAttributedString *strFS = [[NSMutableAttributedString alloc] init];
UIColor *color = [UIColor yellowColor]; // select needed color
NSDictionary *attrs = @{ NSForegroundColorAttributeName : color};
NSDictionary *attrsLab = @{ NSForegroundColorAttributeName : [UIColor whiteColor]};
for(int i = 0; i <arrLabelData.count; i++)
{
NSString *strLabData = [arrLabelData objectAtIndex:i];
NSString *strLab = [arrLabel objectAtIndex:i];
NSAttributedString *attStringLab = [[NSAttributedString alloc] initWithString:strLab attributes:attrsLab];
NSAttributedString *attStringLabData = [[NSAttributedString alloc] initWithString:strLabData attributes:attrs];
[strFS appendAttributedString:attStringLab];
[strFS appendAttributedString:attStringLabData];
}
lblAttributes.attributedText = strFS;
나는 사용자가 줄 내부 탭 데이터 만 응답 할 :
는이 같은 막대 차트를 설정합니다.
아무도 아이디어가 있으시나요?, 도와주세요.
미리 감사드립니다.
고마워 친구, 그것은 매우 잘 작동 ... – user2017279
메신저는 포드를 사용하는 경우. souce 코드를 편집 할 수 없습니까? ia는 다른 방법으로 stear? –
버전 3.0.4와 동일한 작업 수행 방법 –