swimlane / ngx-charts

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

ngx-charts-number-card[customColors] passes the name and not the value #904

Open ciukstar opened 6 years ago

ciukstar commented 6 years ago

I'm submitting a ... (check one with "x")

Current behavior ngx-charts-number-card[customColors] passes the name and not the value

Expected behavior ngx-charts-number-card[customColors] passes the value and not the name (as in documentation: "custom colors for the chart. Used to override a color for a specific value"). Ideally should inject the name and the value as a whole object {"name": "the name", "value": "the value"}

Reproduction of the problem the-template.html

<ngx-charts-number-card
    [view]="viewSize"
    [customColors]="colorFun"
    [results]="ratings">
  </ngx-charts-number-card>

the-component.ts

colorFun(x: any): string {
    console.log('colorFun: x:', x);
    //Not working because x is the name and not the value
    // return x < 1.5 ? 'red' : (x < 1.7 ? 'yellow' : 'green');
    // return x.value < 1.5 ? 'red' : (x.value < 1.7 ? 'yellow' : 'green');
    return 'green';
  }

What is the motivation / use case for changing the behavior? Conformance with the documentation.

Please tell us about your environment:

Linux, Emacs, npm

romanfedyshyn commented 5 years ago

@ciukstar here you find a solution your issue, it's work for me - #269

ciukstar commented 5 years ago

Thanks for suggestion. I don't think #269 is a solution for me. It seems that for other charts, ngx-charts passes the "entire" object {name: string, value: number} to [customColors] function, but not for ngx-charts-number-card for some reason. I tried #269 but my data is retrieved async and for some reason *ngIf does not work and [customColors] has no binding data .... Kinda weird. Anyway, I replaced all this ngx-charts-number-card with a simple mat-grid-list and some animations. Thanks for the tip! (Maybe I should close this issue?!)

golavr commented 4 years ago

ngx-charts: v13.0.0 same problem w/ ngx-charts-bar-vertical. the object should be passed and not the name.

martheli commented 4 years ago

+1 on this issue. When trying to use customColors I want the object to be passed so that for vertical stacked bar chart I have the data for the bar and each stack. The hover label has the information.

hardasbricks commented 4 years ago

+1 ngx-linechart also only passes the name instead of the object.

hevans90 commented 4 years ago

same for horizontal bar charts - this is really a missing feature because we can't set custom colors based on values of the datasets...

developerzzz commented 2 years ago

same for horizontal bar charts - not able to pass object