XAxis labels position
- Dominant language
- Swift
- Stars
- 28k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I have a xaxis labels i want to be just underneath of bars in BarChartView

But as you can see, there is a misplaced labels.
XAxisRenderer.swift:211 shows me the following xAxis.entries:
0 : 1495530709.7142859 - 23.05 09:11:49
1 : 1495631273.1428573 - 24.05 13:07:53 (27:56:04 diff)
2 : 1495731836.5714288 - 25.05 17:03:56 (27:56:03 diff)
3 : 1495832400.0000002 - 26.05 21:00:00 (27:56:04 diff)
4 : 1495932963.4285717 - 28.05 00:56:03 (27:56:04 diff)
5 : 1496033526.8571432 - 29.05 04:52:06 (27:56:03 diff)
6 : 1496134090.2857146 - 30.05 08:48:10 (27:56:04 diff)
XAxisRenderer.swift:211 shows me the following position.x:
0: 45.81
1: 78.81 (33 diff)
2: 121.85 (33 diff)
3: 169.89 (43 diff)
4: 207.92 (37 diff)
5: 250.96 (32 diff)
6: 283.89 (32 diff)
I guess the problem may be in
XAxisRenderer.swift:200
let valueToPixelMatrix = transformer.valueToPixelMatrix
Any suggestions?
P.S.:
```
// BarChartView settings:
ChartXAxis* xaxis = _chartView.xAxis;
DateAxisValueFormatter* dateFormatter = [[DateAxisValueFormatter alloc] init];
xaxis.drawGridLinesEnabled = YES;
xaxis.drawAxisLineEnabled = YES;
xaxis.drawLabelsEnabled = YES;
xaxis.labelPosition = XAxisLabelPositionBottom;
xaxis.labelTextColor = [UIColor whiteColor];
xaxis.valueFormatter = dateFormatter;
xaxis.labelFont = [UIFont systemFontOfSize:7];
xaxis.avoidFirstLastClippingEnabled = YES;
xaxis.forceLabelsEnabled = YES;
xaxis.forceLabelsCount = 7;
```
```
// DateAxisValueFormatter.m
- (NSString*)stringForValue:(double)value axis:(ChartAxisBase *)axis {
NSDate* date = [NSDate dateWithTimeIntervalSince1970:value];
NSDateFormatter* toFormatter = [[NSDateFormatter alloc] init];
[toFormatter setDateFormat:@"dd.MM"];
NSString* res = [toFormatter stringFromDate:date];
return res;
}
```
Contributor guide
Research direction
Start with XAxisRenderer.swift around lines 200-211 and inspect how the valueToPixelMatrix maps the forced x-axis entries to label positions. Reproduce the BarChartView setup with forceLabelsEnabled and forceLabelsCount set to 7, then compare the rendered positions with the DateAxisValueFormatter.m output. Done means the date labels appear at the intended positions underneath the bars without breaking other x-axis rendering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100