Skip to content

Can't plot a Promise from a DuckDBClient #912

Closed Answered by mbostock
jaanli asked this question in Q&A
Discussion options

You must be logged in to vote

I suggest that you define income as a top-level variable so that you can use implicit await across code blocks, and also so you only recompute income when the selectedYear changes (and not also on resize):

```js
const income = db.query(`
  SELECT income, count, sector FROM data
  WHERE year = ${selectedYear}
`); 
```

Then you pass the already-computed income data to your incomeChart function, rather than querying within the chart (and once again the incomeChart function doesn’t need to be async, which makes it compatible with resize):

```js
function incomeChart(income, width) {
  return Plot.plot({
    width,
    marginLeft: 60,
    x: { type: "log" },
    color: { legend: "swatches", col…

Replies: 7 comments 3 replies

Comment options

You must be logged in to vote
0 replies

This comment has been minimized.

Comment options

You must be logged in to vote
1 reply
@mbostock
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by jaanli
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Fil
Comment options

@jaanli
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn’t working
3 participants
Converted from issue

This discussion was converted from issue #911 on February 25, 2024 08:16.