Inline Data
Embed data directly in your chart configuration. Best for small datasets, demos, and quick prototyping.
Basic Syntax
Use source with a JSON string:
markdown
```dg
type: bar
data:
source: '[{"product": "Apples", "count": 10}, {"product": "Oranges", "count": 7}]'
x: product
y: count
title: Fruit Inventory
```JSON Array Format
The most common format - an array of objects:
yaml
data:
source: '[
{"name": "Alice", "score": 85},
{"name": "Bob", "score": 92},
{"name": "Carol", "score": 78}
]'Each object becomes a row. Keys become column names.
Multi-Line Format
Use YAML multi-line syntax for readability:
yaml
data:
source: |
[
{"date": "2024-01", "revenue": 1200},
{"date": "2024-02", "revenue": 1450},
{"date": "2024-03", "revenue": 1320}
]Single Object Format
For key-value pairs, use an object:
yaml
data:
source: '{"apples": 10, "oranges": 7, "bananas": 5}'DataGlass converts this to:
| key | value |
|---|---|
| apples | 10 |
| oranges | 7 |
| bananas | 5 |
Use x: key and y: value to access.
Data Types
Values are automatically parsed:
| Input | Type |
|---|---|
"hello" | String |
42 | Number |
3.14 | Number |
true / false | Boolean |
null | Null |
"2024-01-15" | String (parsed as date for time axes) |
Complete Example
markdown
```dg
type: line
data:
source: |
[
{"month": "Jan", "sales": 4200, "region": "North"},
{"month": "Feb", "sales": 3800, "region": "North"},
{"month": "Mar", "sales": 5500, "region": "North"},
{"month": "Jan", "sales": 3100, "region": "South"},
{"month": "Feb", "sales": 2900, "region": "South"},
{"month": "Mar", "sales": 4200, "region": "South"}
]
x: month
y: sales
color: region
title: Regional Sales Comparison
```Tips
Keep It Small: Inline data is stored in your note. For datasets over 50 rows, use a file instead.
Quote the JSON: The entire JSON string must be quoted with single quotes (
').
Use Multi-Line: The YAML
|syntax makes large inline data much more readable.
Common Mistakes
Wrong: Unquoted JSON
yaml
data:
source: [{"x": 1}] # Error: YAML parses this incorrectlyRight: Quoted JSON
yaml
data:
source: '[{"x": 1}]' # Correct: String containing JSONWrong: Double quotes around JSON
yaml
data:
source: "[{\"x\": 1}]" # Messy escapingRight: Single quotes outside
yaml
data:
source: '[{"x": 1}]' # CleanSee Also
- File Data - For larger datasets
- Transformations - Process data after loading