我在Charts
图库中遇到问题。
我正在使用HorizontalBarChartView
获得以下问题:
以下是我的图表设置代码:
- (void)setupBarChartForPinData {
switch (_selectedLegend) {
case kAppGraphAllLegend:
_barPinChartHeightConstarins.constant = (self.mutArrPinList.count*2)*15;
break;
case kAppGraphLegend1:
_barPinChartHeightConstarins.constant = (self.mutArrPinList.count*15);
break;
case kAppGraphLegend2:
_barPinChartHeightConstarins.constant = self.mutArrPinList.count*15;
break;
default:
break;
}
[UIView animateWithDuration:0.2
animations:^{
// Called on parent view
[self.view layoutIfNeeded];
_scrView.contentSize = CGSizeMake(_scrView.contentSize.width,_containerView.frame.size.height + 8 );
}];
_barChartPins.delegate = self;
_barChartPins.drawBarShadowEnabled = NO;
//_barChartPins.minOffset = 0;
_barChartPins.dragEnabled = YES;
_barChartPins.dragDecelerationEnabled = YES;
_barChartPins.chartDescription.enabled = NO;
_barChartPins.drawValueAboveBarEnabled = YES;
_barChartPins.leftAxis.axisMinimum = 0;
ChartXAxis *xAxis = _barChartPins.xAxis;
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.drawGridLinesEnabled = YES;
xAxis.labelCount = self.mutArrPinList.count;
xAxis.valueFormatter = self;
xAxis.drawAxisLineEnabled = YES;
xAxis.labelFont = kAPPCiscoSansTTNormal(10.0);
xAxis.labelTextColor = kAppPrimaryHeading;
ChartYAxis *leftAxis = _barChartPins.leftAxis;
leftAxis.drawGridLinesEnabled = NO;
_barChartPins.leftAxis.enabled = NO;
_barChartPins.leftAxis.drawAxisLineEnabled = NO;
_barChartPins.rightAxis.enabled = NO;
_barChartPins.rightAxis.drawAxisLineEnabled = NO;
_barChartPins.legend.enabled = NO;
[self setPinGraphData];
}
设置数据:
- (void)setPinGraphData
{
NSMutableArray *arrVals1 = [NSMutableArray new];
NSMutableArray *arrVals2 = [NSMutableArray new];
[self.mutArrPinList enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
[arrVals1 addObject:[[BarChartDataEntry alloc]
initWithX:idx
yValues:@[[NSNumber numberWithDouble:[obj[@"outstanding"] doubleValue]]]]];
[arrVals2 addObject:[[BarChartDataEntry alloc]
initWithX:idx
yValues:@[[NSNumber numberWithDouble:[obj[@"incoming"] doubleValue]]]]];
}];
BarChartDataSet *set1 = nil;
BarChartDataSet *set2 = nil;
if (_barChartPins.data.dataSetCount > 0)
{
set1 = (BarChartDataSet *)_barChartPins.data.dataSets[0];
set1.values = arrVals1;
if (_barChartPins.data.dataSetCount > 1) {
set2 = (BarChartDataSet *)_barChartPins.data.dataSets[1];
set2.values = arrVals2;
}
[_barChartPins.data notifyDataChanged];
[_barChartPins notifyDataSetChanged];
}
else
{
set1 = [[BarChartDataSet alloc] initWithValues:arrVals1];
set2 = [[BarChartDataSet alloc] initWithValues:arrVals2];
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
switch (_selectedLegend) {
case kAppGraphAllLegend:{
[set1 setColor:kAppLegend1GraphColor];
[set2 setColor:kAppLegend2GraphColor];
[dataSets addObject:set1];
[dataSets addObject:set2];
break;
}
case kAppGraphLegend1:{
[set1 setColor:kAppLegend1GraphColor];
[dataSets addObject:set1];
break;
}
case kAppGraphLegend2:{
[set2 setColor:kAppLegend2GraphColor];
[dataSets addObject:set2];
break;
}
default:
break;
}
BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];
if (_selectedLegend == kAppGraphAllLegend) {
//Setup fro GroupBars
double groupSpace = 0.3;
double barSpace = 0.05;
double barWidth = 0.3;
// (0.3 + 0.05) * 2 + 0.3 = 1.00 -> interval per "group"
// (baSpace + barWidth) * dataSet count + groupSpace = 1.0
int groupCount = arrVals1.count;
int startYear = 0;
data.barWidth = barWidth;
_barChartPins.xAxis.axisMinimum = startYear;
[data groupBarsFromX:0 groupSpace:groupSpace barSpace:barSpace];
double groupWidth = [data groupWidthWithGroupSpace:groupSpace barSpace:barSpace];
_barChartPins.xAxis.axisMaximum = startYear + groupWidth * groupCount;
_barChartPins.xAxis.centerAxisLabelsEnabled = YES;
}else{
_barChartPins.xAxis.centerAxisLabelsEnabled = NO;
}
[data setDrawValues:YES];
[data setValueTextColor:kAppPrimaryHeading];
[data setValueFont:kAPPCiscoSansTTNormal(8.0f)];
_barChartPins.data = data;
}
}
我正在使用组合栏和单杆,在组合栏中它的工作正常,但在单个栏中切割最后一个条。
任何帮助将不胜感激。
先谢谢。
答案 0 :(得分:0)
我找到了上述问题的解决方案。
正如我所说,我正在为启用组图表创建问题b' cus的条件代码我按照组空间和条宽度手动更改轴最小值和最大值。
const pattern = /^[^/,:<>!_~@#$%^&()+=?()“|!\[#$-]+$/;
console.log(pattern.test('fff>')); // false
console.log(pattern.test('fff')); // true
由于上面的代码,当我删除组并去正常的时候,我的agin采取我的自定义max&amp;最小data.barWidth = barWidth;
_barChartPins.xAxis.axisMinimum = startYear;
_barChartPins.xAxis.axisMaximum = startYear + groupWidth * groupCount;
值,因此我们必须重置xAxis
分钟&amp;最大如下。
xAxis
这将解决我在top&amp; amp;在底部切割条。
希望这会帮助其他人解决同样的问题。
感谢。