Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data label inside bar #1892

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kedij777
Copy link

@kedij777 kedij777 commented Aug 2, 2023

What kind of change does this PR introduce? (check one with "x")

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)
Issue #1389

What is the new behavior?
Data label can be displayed inside the bar for vertical and horizontal bar chart. In the context of a vertical bar chart, when the data label's width exceeds the corresponding bar, the label will be abbreviated and displayed in a rounded format, for example, as "10k" instead of "10402".

image image

Pasted Graphic 8

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

@AlejandroAgRa
Copy link

How to implement this new feature, Data Label inside the bar

@kedij777
Copy link
Author

kedij777 commented Jan 7, 2024

How to implement this new feature, Data Label inside the bar

Hi AlejandroAgRa, I believe if you clone this branch kedij777:data_label_inside_bar, run it on your local laptop, click 'show data label' and change data label position to 'inside bar', you should be able to replicate the feature.
image

}

calculateWidth(value): number {
//for default font size of 11px, the width of a single digit number is 6.29 and width of comma is 3.21, the width of 'K','B','M' is about 5.66
Copy link

Choose a reason for hiding this comment

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

Add space after // to match coding style

Suggested change
//for default font size of 11px, the width of a single digit number is 6.29 and width of comma is 3.21, the width of 'K','B','M' is about 5.66
// for default font size of 11px, the width of a single digit number is 6.29 and width of comma is 3.21, the width of 'K','B','M' is about 5.66

@@ -97,6 +98,8 @@ export class SeriesHorizontal implements OnChanges {
@Input() showDataLabel: boolean = false;
@Input() dataLabelFormatting: any;
@Input() noBarWhenZero: boolean = true;
@Input() dataLabelPosition: string;

Copy link

Choose a reason for hiding this comment

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

Remove extra newline

Suggested change

@@ -47,6 +48,7 @@ export class BarLabelComponent implements OnChanges {
formatedValue: string;
transform: string;
textAnchor: string;
orginalVal: any;
Copy link

Choose a reason for hiding this comment

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

Is this supposed to be originalVal?

if (this.value < 0) {
this.x = this.x - this.horizontalPadding;
this.textAnchor = 'end';
var valueWidth = this.calculateWidth(this.value);
Copy link

Choose a reason for hiding this comment

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

Use let instead of var to avoid issues related to scope and match coding style.

@@ -1329,6 +1331,13 @@ <h3 (click)="optsVisible = !optsVisible" style="cursor: pointer">
<option value="below">Below</option></select
><br />
</div>
<div *ngIf="chart.options.includes('dataLabelPosition')">
Copy link

Choose a reason for hiding this comment

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

The dropdown for data label position on the demo should be placed after the show data label checkbox for better user experience. Currently it's placed after legend position.
Screenshot 2024-01-09 at 5 53 40 PM

@@ -18,6 +18,7 @@ const chartGroups = [
'showLegend',
'legendTitle',
'legendPosition',
'dataLabelPosition',
Copy link

Choose a reason for hiding this comment

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

Show data label is supported for 8 charts currently - standard, stacked, grouped vertical bar chart, standard stacked, grouped horizontal bar chart and negative stacked horizontal and vertical bar charts. However, data label inside bar is only supported for standard vertical and horizontal bar charts. Is it possible to add the feature to the rest of the charts that support data label?

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.

3 participants