Plot a Table of CSV in dataviewjs

What I’m trying to do

Plot a Table of CSV in dataviewjs, in simple/clean manner.
It shows nothing.

```dataviewjs
const data = await dv.io.csv("my_csv.csv");
dv.table(["Ticket", "Profit"], data)
```

Things I have tried

I read the dataviewjs documents this thread and wrote the code above and below:

```dataview
TABLE WITHOUT ID Ticket, Profit
FROM csv("my_csv.csv")
```

This dataview code works perfectly fine.

However, the problem lies in the first code of dataviewjs as it does not show anything, not even an error message.

In console, it says:
Uncaught (in promise) TypeError: row.map is not a function

My interpretation is that map is a function of n DataArray, not an object, and the “data” is an array of objects. So, I wonder how everyone plots a table of CSV in DataViewJS as simply as that.

So, this freaking ugly code works:

```dataviewjs
const data = await dv.io.csv("my_csv.csv")
console.log(data)
const data_arr = data.array()

// Make a array of arrays
let data_arr_arr = []
for (let i in data_arr) {
	const dict = data_arr[i]
	// dict to array of values
	data_arr_arr[i] = Object.keys(dict).map(function(key){return dict[key];});
	
}
dv.table(["Ticket", "Profit"], data_arr_arr.map(r => [r[0], r[2]]))
```

Is this what everyone doing?

my_csv.csv:
Ticket,Profit
1,68.54
2,55.60
3,77.12

You need to map the data returned from csv read, the following worked for me:

```dataviewjs
const data = await dv.io.csv("my_csv.csv")

dv.table(["Ticket", "Profit"],
  data.map(r => [r.ticket, r.profit]))
```
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.