Skip to content

fix(Chart): stacked bar ShowDataLabel has overlapping text#1058

Merged
ArgoZhang merged 3 commits into
masterfrom
dev-chart
Jul 11, 2026
Merged

fix(Chart): stacked bar ShowDataLabel has overlapping text#1058
ArgoZhang merged 3 commits into
masterfrom
dev-chart

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jul 11, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #1057

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Bug Fixes:

  • Resolve overlapping data labels in stacked bar charts by conditionally displaying labels only for non-zero bar values.

@bb-auto bb-auto Bot added the enhancement New feature or request label Jul 11, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Jul 11, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts chart data label display logic so stacked bar charts only show labels for non-zero values, preventing overlapping text, and updates the chart project metadata.

Sequence diagram for stacked bar chart data label display logic

sequenceDiagram
    participant ChartComponent
    participant getChartOption
    participant ChartJS

    ChartComponent->>getChartOption: getChartOption(option)
    getChartOption->>getChartOption: read option.options.showDataLabel
    alt x axis stacked and showDataLabel true
        getChartOption->>ChartJS: set dataLabels.display = showDataLabel(context)
        ChartJS->>ChartJS: showDataLabel(context)
        alt Number(context.dataset.data[context.dataIndex]) !== 0
            ChartJS->>ChartJS: render data label
        else Number(...) === 0
            ChartJS->>ChartJS: skip data label
        end
    else not stacked or showDataLabel not true
        getChartOption->>ChartJS: set dataLabels.display = option.options.showDataLabel
    end
Loading

File-Level Changes

Change Details Files
Refine stacked bar chart data label display so labels are conditionally shown based on the data point value to avoid overlap.
  • Introduce a local showDataLabel variable derived from option.options.showDataLabel.
  • Override showDataLabel with a formatter function when x-axis stacking is enabled and labels are requested.
  • Use the computed showDataLabel value as the display configuration for data labels instead of the raw option.
src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js
Update chart project file to reflect the change (e.g., versioning or metadata adjustments).
  • Modify BootstrapBlazor.Chart.csproj to capture the new chart behavior change.
src/components/BootstrapBlazor.Chart/BootstrapBlazor.Chart.csproj

Assessment against linked issues

Issue Objective Addressed Explanation
#1057 Fix the stacked bar chart ShowDataLabel behavior so that data labels do not overlap (e.g., by conditionally hiding labels that cause overlap).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@ArgoZhang ArgoZhang merged commit 769da48 into master Jul 11, 2026
3 checks passed
@ArgoZhang ArgoZhang deleted the dev-chart branch July 11, 2026 05:33

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Accessing option.options.x.stacked without checking that options.x exists may throw if x-axis config is omitted; consider guarding this access or providing a safe default.
  • The data label display condition Number(...) !== 0 will show labels for negative values and NaN; if the intent is to hide labels on zero-height bars only, consider a stricter check (e.g. > 0) or explicitly handling non-numeric values.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Accessing `option.options.x.stacked` without checking that `options.x` exists may throw if x-axis config is omitted; consider guarding this access or providing a safe default.
- The data label display condition `Number(...) !== 0` will show labels for negative values and `NaN`; if the intent is to hide labels on zero-height bars only, consider a stricter check (e.g. `> 0`) or explicitly handling non-numeric values.

## Individual Comments

### Comment 1
<location path="src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js" line_range="385" />
<code_context>

+    let showDataLabel = option.options.showDataLabel;
+    if (showDataLabel === true && option.options.x.stacked) {
+        showDataLabel = context => Number(context.dataset?.data[context.dataIndex]) !== 0;
+    }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Refine the zero-check logic to avoid treating `undefined`/`null` as non-zero values.

`Number(context.dataset?.data[context.dataIndex]) !== 0` will treat `undefined`, `null`, or non-numeric values as `NaN`, which still passes the `!== 0` check, so labels may appear for missing/invalid data. Use a more explicit guard, e.g.:

```ts
const v = context.dataset?.data[context.dataIndex];
return v != null && Number(v) !== 0;
```

to restrict labels to meaningful, non-zero values.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


let showDataLabel = option.options.showDataLabel;
if (showDataLabel === true && option.options.x.stacked) {
showDataLabel = context => Number(context.dataset?.data[context.dataIndex]) !== 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Refine the zero-check logic to avoid treating undefined/null as non-zero values.

Number(context.dataset?.data[context.dataIndex]) !== 0 will treat undefined, null, or non-numeric values as NaN, which still passes the !== 0 check, so labels may appear for missing/invalid data. Use a more explicit guard, e.g.:

const v = context.dataset?.data[context.dataIndex];
return v != null && Number(v) !== 0;

to restrict labels to meaningful, non-zero values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(Chart): stacked bar ShowDataLabel has overlapping text

1 participant