angularbar-chartaxisonselectngx-charts

Angular ngx-charts how to get x axis number


I have an Angular Ngx vertical chart , and I need to get only x axis number. I want to use this x axis number at onSelect function.

Html :

  <ngx-charts-bar-vertical
        [xAxisLabel]="xAxisLabel"
        [yAxisLabel]="yAxisLabel"
        (select)="onSelect($event)"
        [results]="dataSource">
  </ngx-charts-bar-vertical>

DataSource :

[ {userId: 5, name: "User Name example", value: 69.6} ... ]

I want to get "userId" part in fact, but i couldn't . When I select a bar , onSelect is getting only the "name" and the "value" parts, but not 'userId' part.

In reality, i want that the exactly opposite of this stuff : https://github.com/swimlane/ngx-charts/issues/409
Here want to hide allData but i want to get all data when i click a bar.

So i think that :

How can i do that ?


Solution

  • I found a simple solution : Added an extra field only , and it's Ok.

    Now my dataSource is like that :

    { name: 'User Name', value: 40,32, extra: { userId: 17 }

    so now i can get extra field, then I can get use userId field .

    It helped me : https://github.com/swimlane/ngx-charts/issues/506