Reputation: 871
I'm trying to use inline csv data with Vega charts, using the values property of the Vega data specification. The Vega documentation says that this possible, but doesn't give an example. I have tried to change the bar chart example from the examples gallery to use inline CSV data instead of JSON, but without success.
I replaced the data section from the example code with my own code. The original snippet looks like this:
"data": [
{
"name": "table",
"values": [
{"category": "A", "amount": 28},
{"category": "B", "amount": 55},
{"category": "C", "amount": 43},
{"category": "D", "amount": 91},
{"category": "E", "amount": 81},
{"category": "F", "amount": 53},
{"category": "G", "amount": 19},
{"category": "H", "amount": 87}
]
} ]
I replaced it with this one:
"data": [
{
"name": "table",
"format": "csv",
"values": {"category", "amount"
"A", "28"
"B", "55"
"C", "43"
"E", "91"
"E", "81"
"F", "53"
"G", "19"
"H", "87"}
} ]
I used the Vega online editor, but got only error messages about unexpected tokens in the JSON. I also tried the following variation:
"data": [
{
"name": "table",
"format": "csv",
"values": "category, amount
A, 28
B, 55
C, 43
E, 91
E, 81
F, 53
G, 19
H, 87"
} ]
But this lead to the same error messages. What is the correct syntax here?
Upvotes: 0
Views: 854
Reputation: 5688
The way, as you can view in the documentation, is something like this:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A simple bar chart with embedded data.",
"data": {"values": "a,b\nA,50\nB,30\nC,60", "format": {"type": "csv"}},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "nominal", "axis": {"labelAngle": 0}},
"y": {"field": "b", "type": "quantitative"}
}
}
An example here
Upvotes: 1