【问题标题】:Showing duplicate labels on X-Axis在 X 轴上显示重复的标签
【发布时间】:2017-08-25 08:43:51
【问题描述】:

我正在使用Charts framework (danielgindi/Charts)。我的折线图在 x 轴上显示重复的标签,如果我的标签数组上只有一个值可用(在这种情况下为xAxisLabels)。见下图。

如何确保标签不会重复?因此,如果标签数组上只有一个可用条目,那么它应该在最左侧只显示一个标签。其他标签为空白,将在标签数组可用时逐渐填充。

这是我迄今为止尝试过的代码。非常感谢您的帮助。

@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]];
}

【问题讨论】:

    标签: ios objective-c charts linechart ios-charts


    【解决方案1】:

    尝试使用:

    self.chartView.xAxis.granularityEnabled = true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 2019-04-13
      • 2021-12-08
      • 2019-07-28
      • 2021-12-30
      • 2021-12-03
      • 1970-01-01
      相关资源
      最近更新 更多