Skip to content

Select nested data keys from a dataset for plots #1050

Answered by mbostock
captain-yoshi asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can use a function accessor: {x: d => d.query.request, y: d => d.metrics.time}. Though I think in your case you may need to flatten your data, as the d.metrics.time is an array of samples and Plot.boxY will expect a single number. That might look like this…

Plot.plot({
  marks: [
    Plot.boxY(data.flatMap(d => d.metrics.time.map(t => ({request: d.query.request, time: t}))), {x: "request", y: "time"})
  ]
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@captain-yoshi
Comment options

Answer selected by captain-yoshi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1049 on September 15, 2022 20:17.