Skip to content

Allow bar chart data labels to be positioned outside the bars (#500)#981

Open
timmolter wants to merge 1 commit into
developfrom
issue-500-bar-labels-outside
Open

Allow bar chart data labels to be positioned outside the bars (#500)#981
timmolter wants to merge 1 commit into
developfrom
issue-500-bar-labels-outside

Conversation

@timmolter

Copy link
Copy Markdown
Member

Fixes #500.

Problem

Before 3.6.4, bar chart value labels could be drawn outside (on top of) the bars. That ability was lost when the configurable labelsPosition was introduced (#402) and clamped to [0, 1], which only allows placement inside the bar (baseline → top). Users asked for the "labels on top" behavior back.

Changes

  • CategoryStyler / HorizontalBarStyler: relax the labelsPosition upper cap so values greater than 1 are allowed (still rejects < 0); javadoc documents the new semantics.
  • PlotContent_Category / PlotContent_HorizontalBar: for labelsPosition > 1, draw the label outside the bar at a fixed pixel gap that does not scale with the bar's size — gap = (labelsPosition - 1) * 100 pixels (e.g. 1.1 → 10px). The inside [0, 1] behavior (a fraction of the bar) is unchanged. Earlier the outside distance scaled with bar height, so taller bars pushed their labels much farther out — fixed here.
  • Automatic label font color: when a label is drawn outside the bar it sits on the plot background, so the automatic contrast color is now computed against the plot background instead of the bar fill. This keeps outside labels legible without setting a color manually, and also fixes the stack-sum total labels (which are always drawn outside).
  • AxisPair: automatically reserve axis headroom when labels are drawn outside, so they are not clipped at the plot edge (no need to set manual axis min/max).

Demos

  • Enabled outside labels in BarChart04 and HorizontalBarChart01.
  • Added TestForIssue500 and TestForIssue500_HorizontalBar standalone issue charts (positive and negative values).

Testing

  • All 93 existing unit tests pass.
  • Verified rendering for vertical and horizontal bars, positive and negative values, and varying bar heights (the outside gap is now constant regardless of bar size, and labels are no longer clipped).

🤖 Generated with Claude Code

@timmolter timmolter force-pushed the issue-500-bar-labels-outside branch from 325de34 to 9d1b855 Compare June 23, 2026 09:52
Restores the ability (present in 3.6.1) to place bar chart value labels
outside the bars, which was lost when the configurable labelsPosition was
added and clamped to [0, 1] (inside only).

- CategoryStyler/HorizontalBarStyler: relax the labelsPosition cap so values
  greater than 1 are allowed; document the semantics.
- PlotContent_Category/PlotContent_HorizontalBar: for labelsPosition > 1,
  draw the label outside the bar at a fixed pixel gap that does not scale
  with the bar's size: gap = (labelsPosition - 1) * 100 pixels. The inside
  [0, 1] behavior (fraction of the bar) is unchanged.
- Compute the automatic label font color against the plot background, not the
  bar fill, when the label is drawn outside the bar so it stays legible (also
  fixes stack-sum labels).
- AxisPair: reserve axis headroom automatically when labels are drawn outside
  so they are not clipped at the plot edge.
- Demos: show outside labels in BarChart04 and HorizontalBarChart01, and add
  TestForIssue500 / TestForIssue500_HorizontalBar.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@timmolter timmolter force-pushed the issue-500-bar-labels-outside branch from 9d1b855 to 995255f Compare June 23, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If it is possiable for set the value to the top for bar chart, but not inner(version 3.6.4) .

1 participant