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

[Bug]: Exporting as CSV from Donut/Pie chart doesn't work with valueMapsTo #1693

Open
1 task
ShivaJormungandr opened this issue Dec 5, 2023 · 1 comment
Open
1 task
Assignees

Comments

@ShivaJormungandr
Copy link

ShivaJormungandr commented Dec 5, 2023

Name

Octavian Saftoiu

Are you an IBM employee?

  • Yes

What happened?

A bug happened!

Summary

Export as CSV and view tabular data don't work when you don't have a "value" column even though the value is mapped to another column that exists.

What I expected to happen

The chart looks as expected. I expected taht I can export the data I see in the chart.

What I think is the issue

The issue seems to stem from the fact that getTabularDataArray() from pie.ts does not use valueMapsTo like it uses groupMapsTo, but the key 'value' is hardcoded.

The offending piece of code in core/src/model/pie.ts:

getTabularDataArray() {
  const displayData = this.getDisplayData()
  const options = this.getOptions()
  const { groupMapsTo } = options.data
  
  const result = [
    ['Group', 'Value'],
      ...displayData.map((datum: any) => [
        datum[groupMapsTo],
        datum['value'] === null ? '–' : datum['value'].toLocaleString()
    ])
  ]
  
  return result
}

Version

"@carbon/charts-svelte": "^1.13.8"

Data & options used

Data for chart:

[
  {
    "group": "Test 1",
    "test": 1000
  },
  {
    "group": "Test 2",
    "test": 299
  },
  {
    "group": "Test 3",
    "test": 333
  },
  {
    "group": "Test 4",
    "test": 1000
  },
  {
    "group": "Test 5",
    "test": 299
  },
  {
    "group": "Test 6",
    "test": 333
  }
]


Options:
```JSON
{
  "title": "Pie",
  "resizable": true,
  "height": "400px",
  "theme": "g100",
  "pie": {
    "valueMapsTo": "test"
  }
}


### Relevant log output

```js
pie.ts:36 Uncaught TypeError: Cannot read properties of undefined (reading 'toLocaleString')
    at pie.ts:36:58
    at Array.map (<anonymous>)
    at yt2.getTabularDataArray (pie.ts:34:19)
    at rc2.getModalHTML (modal.ts:74:33)
    at DocumentFragment.handleShowModal (modal.ts:35:24)
    at ot4.dispatchEvent (events.ts:31:25)
    at Object.clickFunction (toolbar.ts:535:48)
    at Hs2.triggerFunctionAndEvent (toolbar.ts:355:12)
    at HTMLButtonElement.<anonymous> (toolbar.ts:110:14)
    at HTMLButtonElement.<anonymous> (on.js:3:14)

Codesandbox example

It happens in this example. Export as CVS and See as table are not working.
https://charts.carbondesignsystem.com/svelte/?path=/story/simple-charts-donut--donut-value-maps-to-count

What priority level would this be in your opinion?

P2

@ShivaJormungandr
Copy link
Author

Hey. I think that the #1698 merge fixed this. Should this issue be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants