Tweak x-axis labels of charts (#4733)

* Avoid overlapping of labels

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2025-05-19 08:58:15 +02:00
committed by GitHub
parent cb42343c3e
commit 3211e2012d
@@ -206,6 +206,11 @@ public class DefaultChartProvider implements ChartProvider {
} }
styler.setYAxisTickMarkSpacingHint(yAxisSpacing); styler.setYAxisTickMarkSpacingHint(yAxisSpacing);
styler.setYAxisLabelAlignment(TextAlignment.Right); 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 // chart
styler.setChartBackgroundColor(chartTheme.getChartBackgroundColor()); styler.setChartBackgroundColor(chartTheme.getChartBackgroundColor());
styler.setChartFontColor(chartTheme.getChartFontColor()); styler.setChartFontColor(chartTheme.getChartFontColor());