2017-08-25 4 views
0

Charts framework (danielgindi/Charts)を使用しています。私の折れ線グラフは、ラベル配列(この場合はxAxisLabels)に1つの値しかない場合、x軸に重複したラベルを表示しています。下の画像を参照してください。X軸に重複ラベルが表示される

enter image description here

どのように私はラベルが重複されないことを保証することができますか?したがって、ラベル配列に利用可能なエントリが1つしかない場合は、最も左側のラベルが1つだけ表示されます。他のラベルは空白になり、ラベル配列の空き状況に応じて徐々に埋められます。

ここまで私が試したコードです。ご助力ありがとうございます。

@property (nonatomic) LineChartView* chartView; 
@property (strong, nonatomic) NSArray<NSString *> *xAxisLabels; 

- (void)configureChartViewIfNeeded { 
    self.chartView.drawGridBackgroundEnabled = NO; 
    self.chartView.legend.enabled = NO; 
    self.chartView.minOffset = 28; 

    self.chartView.xAxis.enabled = YES; 
    self.chartView.xAxis.labelPosition = XAxisLabelPositionBottom; 
    self.chartView.xAxis.labelTextColor = [UIColor colorWithWhite:1 alpha:0.79]; 
    self.chartView.xAxis.gridColor = [UIColor colorWithWhite:1 alpha:0.79]; 
    self.chartView.xAxis.drawAxisLineEnabled = NO; 
    self.chartView.xAxis.drawGridLinesEnabled = NO; 

    self.chartView.leftAxis.labelTextColor = [UIColor colorWithWhite:1 alpha:0.79]; 
    self.chartView.leftAxis.gridColor = [UIColor colorWithWhite:1 alpha:0.3]; 
    self.chartView.leftAxis.gridLineWidth = 1.0f; 
    self.chartView.leftAxis.drawZeroLineEnabled = NO; 
    self.chartView.leftAxis.drawAxisLineEnabled = NO; 
    [self.chartView.leftAxis setLabelCount:leftAxisLabelCount force:NO]; 
    self.chartView.leftAxis.drawTopYLabelEntryEnabled = YES; 
    self.chartView.leftAxis.axisMinimum = 0; 
    JVNImpactMetricsFormatter *numberFormatter = [[JVNImpactMetricsFormatter alloc] init]; //My custom formatter 
    [numberFormatter setUsesGroupingSeparator:YES]; 
    [numberFormatter setGroupingSeparator:@","]; 
    [numberFormatter setGroupingSize:3]; 
    numberFormatter.maximumFractionDigits = 1; 
    self.chartView.xAxis.valueFormatter = numberFormatter; //Will present integer values 

    self.chartView.rightAxis.enabled = NO; 

    self.chartView.dragEnabled = NO; 
    self.chartView.scaleXEnabled = self.chartView.scaleYEnabled = NO; 
    self.chartView.drawBordersEnabled = NO; 
    self.chartView.doubleTapToZoomEnabled = NO; 
    self.chartView.delegate = self; 

    self.chartView.descriptionText = @""; 
    [self.chartView animateWithXAxisDuration:0.3 yAxisDuration:0.3]; 
} 


#pragma mark - IChartAxisValueFormatter 

- (NSString * _Nonnull)stringForValue:(double)value axis:(ChartAxisBase * _Nullable)axis { 
    return self.xAxisLabels[[@(value) intValue]]; 
} 

答えて

0

使用してみてください:

self.chartView.xAxis.granularityEnabled = true 
関連する問題