swimlane / ngx-charts

:bar_chart: Declarative Charting Framework for Angular
https://swimlane.github.io/ngx-charts/
MIT License
4.29k stars 1.15k forks source link

valueFormatting dosen't work #1695

Open yairBepr opened 2 years ago

yairBepr commented 2 years ago

Hi! I using in Advanced Pie Chart. I added valueFormatting function and it work in stackblitz of the exmple https://stackblitz.com/edit/swimlane-pie-chart-advanced-avyv8h?embed=1&file=app/app.component.ts but it dosen't work in my computer.

HTML: image

TS: image

In fact in HTML: image

ngx-charts version @swimlane/ngx-charts": "^19.1.0"

Thanks.

Nurech commented 2 years ago

Seems right. Have you tried using arrow functions for callback?

  formator = (val) => {
    let formatter = new Intl.NumberFormat('ILS', {
      style: 'currency',
      currency: 'ILS'
    });
    return formatter.format(val)
  }

image

yairBepr commented 2 years ago

Thank you, I'm tried, it dosn't matter.

ruifelizardo-affinity commented 2 years ago

I also have the same problem! I use the same arrow function in multiple graphs and the valueFormatting property is not working in the advanced pie chart.

ruifelizardo-affinity commented 2 years ago

I was using a function to update the data, and the formatting just doesnt work on the first load, when updating the data it starts working.

Nagi-ta commented 2 years ago

You can fix this problem if you put [animations]="false" in HTML.

adrienunger commented 2 years ago

I'm currently facing the same problem. However, I observed that this erroneous behaviour only occurs if your results-array was empty before you set your data for the chart.

Here an example:

A possible workaround, if you're hesitant to set animations to false, would be to set your result-array to a slightly altered version of your desired values (I substracted 1 from all values of my result-array), then trigger a change detection with this.changeDetectorRef.detectChanges() and finally set your result-array to your desired values. Such a change should be unnoticeable in the animation of the values in the legend.