question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pie-chart's `labelFormatting` implemented with different functionality than number-card and tree-map

See original GitHub issue

I’m submitting a … (check one with “x”)

[ X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior labelFormatting function for number-card and tree-map allows for formatting a label using ‘label’ and ‘value’ fields in a html string. Eg, modified from demo/app.component.ts, line 552

  gdpLabelFormatting(c) {
    return `label=${c.label}<br/><small class="number-card-label">value=${c.value}</small>`;
  }

labelFormatting function for pie-chart only has access to the ‘label’ field (ie., no access to the ‘value’ field), does not allow inserting html into the formatted return string, uses a fixed maximum width for the formatted label, and forces CAPS for the labels.

Expected behavior labelFormatting functionality should be consistent across components.

Reproduction of the problem Tried implementing the following, then researched code and saw that the pie-chart labelFormatting is implemented differently from number-card and tree-map.

<ngx-charts-pie-chart
    [results]="chartData"
    [view]="view"
...
    [labelFormatting]="setLabelFormatting"
...
  ></ngx-charts-pie-chart>

where:

  setLabelFormatting(c): string {
    return `${c.label}<br/><span class="custom-label-text">${c.value}</span>`;
  }

and:

.custom-label-text {
  background-color: #00b400;
  color: #fff;
}

What is the motivation / use case for changing the behavior? It should be possible to print any chart with enough information to convey the meaning of the chart. For pie-charts, in order for the full meaning of the chart to be represented in a printout, they need to show both the ‘label’ and ‘value’ fields for each slice. An implementation of labelFormatting similar to tree-map and number-card would allow the consuming app to format the labels such that all relevant information is visible on a hard-copy printout.

Please tell us about your environment: MacOs, WebStorm, Webpack (development environment)

  • ngx-charts version: [6.0.0]

  • Angular version: 4.1.2

  • Browser: [all]

  • Language: [TypeScript 2.2.2]

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:12
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
doltheadcommented, Oct 19, 2017

Also any html in this returned string is displayed as plain text. setLabelFormatting(label): string { return '<span class="pie-label-text">${label}</span>'; } image

2reactions
elkano91commented, May 14, 2019

Hi, this workaround works find in my project:

var item {}; item['value']=myvalue; item['name']= 'myname'+ ' (' + String(myvalue) + ')';

Not ideal but at least values are added close to my label which is what I wanted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

swimlane/ngx-charts - Gitter
Is there an example on how to implement [labelFormatting]="....." functionality for number-card, pie-chart, and tree-map? Based on the ngx-charts repo's ...
Read more >
How Treemaps are better than Pie Chart
Exploring different data visualization techniques used for visualizing Part of the Whole relationship like pie-chart, donut charts and treemaps.
Read more >
Using labelFormatting in ngx-chart pie
Is an example on how to implement [labelFormatting]="....." functionality for pie-chart. I tried implementing (below) on pie-chart:
Read more >
Changelog - ngx-charts - GitBook
Feature : Implemented min value scales for vertical and horizontal bar charts ... Enhancement: Added label formatting input to number card chart (#332)....
Read more >
Treemaps vs Pie Charts; Which Is The Better Data ...
In this article, we'll explore why treemaps are better than pie charts when choosing a visualization method for your data.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found