Tweak x-axis labels of charts (#4733)

* Avoid overlapping of labels

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
pull/4823/head
Holger Friedrich 2025-05-19 08:58:15 +02:00 committed by GitHub
parent cb42343c3e
commit 3211e2012d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View File

@ -206,6 +206,11 @@ public class DefaultChartProvider implements ChartProvider {
}
styler.setYAxisTickMarkSpacingHint(yAxisSpacing);
styler.setYAxisLabelAlignment(TextAlignment.Right);
// avoid overlapping labels on x-axis;
// Font.getSize() is related to font height, but will also give an indication of the width;
// pattern is not the actual label, but also gives a rough estimation of the width of the label
int xAxisSpacing = Math.max(width / 15, chartTheme.getAxisTickLabelsFont(dpi).getSize() * pattern.length());
styler.setXAxisTickMarkSpacingHint(xAxisSpacing);
// chart
styler.setChartBackgroundColor(chartTheme.getChartBackgroundColor());
styler.setChartFontColor(chartTheme.getChartFontColor());