Skip to content

Pre-grouped data in JSON input? #7523

Answered by jakevdp
kevreth asked this question in Q&A
Discussion options

You must be logged in to vote

This is what the Fold transform is used for. For example:

{
  "data": {
    "values": [
      {"Year": 2002, "Rentals": 184, "Sales": 84},
      {"Year": 2003, "Rentals": 180, "Sales": 67}
    ]
  },
  "transform": [{"fold": ["Rentals", "Sales"], "as": ["type", "value"]}],
  "mark": "bar",
  "encoding": {
    "x": {"field": "value", "type": "quantitative"},
    "y": {"field": "Year", "type": "ordinal"},
    "color": {"field": "type", "type": "nominal"}
  }
}

Replies: 1 comment 1 reply

Comment options

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

Answer selected by domoritz
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