fix: label binding auto-enables data labels on bar chart

When a field is dragged to the 'label' slot, data labels are
automatically shown on top of each bar with the value.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hailin 2026-04-05 02:47:43 -07:00
parent 10b50bb2e0
commit 53669b66b8
1 changed files with 6 additions and 1 deletions

View File

@ -141,13 +141,18 @@ export function buildBarOption(
const xField = xBinding?.columnName ?? ''; const xField = xBinding?.columnName ?? '';
const yField = yBinding?.columnName ?? ''; const yField = yBinding?.columnName ?? '';
const labelBinding = getBinding(bindings, 'label');
const option: Record<string, any> = {}; const option: Record<string, any> = {};
applyCommonStyle(option, style); applyCommonStyle(option, style);
const categories = [...new Set(data.map((row) => String(row[xField])))]; const categories = [...new Set(data.map((row) => String(row[xField])))];
const { xAxis, yAxis } = buildAxisConfig(style, isHorizontal); const { xAxis, yAxis } = buildAxisConfig(style, isHorizontal);
const label = buildLabelConfig(style); // If a label binding exists, force show data labels
const label = labelBinding
? { show: true, position: 'top' as const, fontSize: 12, formatter: '{c}' }
: buildLabelConfig(style);
const colorBinding = getBinding(bindings, 'color'); const colorBinding = getBinding(bindings, 'color');
const splitField = seriesBinding?.columnName ?? colorBinding?.columnName; const splitField = seriesBinding?.columnName ?? colorBinding?.columnName;