📊 Read Chart Tool Examples
The read_chart
tool allows you to display various types of charts and data visualizations directly in the terminal using the rich library.
Chart Types
1. Table Charts
Display data in a formatted table:
{
"type": "table",
"data": [
{"name": "Alice", "age": 30, "department": "Engineering"},
{"name": "Bob", "age": 25, "department": "Marketing"},
{"name": "Charlie", "age": 35, "department": "Sales"}
]
}
2. Bar Charts
Display categorical data as horizontal bars:
3. Pie Charts
Display proportional data as pie segments:
4. Line Charts
Display trends over time or continuous data:
{
"type": "line",
"data": [
{"month": 1, "revenue": 10000},
{"month": 2, "revenue": 12000},
{"month": 3, "revenue": 9500},
{"month": 4, "revenue": 14000}
]
}
Usage Examples
Basic Usage
# Simple table
read_chart(
data={"type": "table", "data": [{"product": "Laptop", "price": 999}, {"product": "Mouse", "price": 25}]},
title="Product Catalog"
)
# Sales data bar chart
read_chart(
data={"type": "bar", "data": {"2023": 50000, "2024": 75000}},
title="Annual Sales",
width=100
)
Advanced Usage
# Complex pie chart with custom dimensions
read_chart(
data={
"type": "pie",
"data": {
"AWS": 40,
"Azure": 30,
"GCP": 20,
"Others": 10
}
},
title="Cloud Provider Market Share",
width=120,
height=25
)
# Multi-series line chart
read_chart(
data={
"type": "line",
"data": [
{"period": "Q1", "sales": 100, "expenses": 80},
{"period": "Q2", "sales": 120, "expenses": 90},
{"period": "Q3", "sales": 110, "expenses": 85},
{"period": "Q4", "sales": 140, "expenses": 100}
]
},
title="Quarterly Performance"
)
Data Formats
Dictionary Format
For simple key-value data:
List of Records Format
For structured data with multiple fields:
{
"type": "table",
"data": [
{"country": "USA", "population": 331000000, "gdp": 21427700},
{"country": "China", "population": 1439323776, "gdp": 14342900},
{"country": "Japan", "population": 126476461, "gdp": 5081770}
]
}
Error Handling
The tool provides helpful error messages:
- Missing data: "⚠️ Warning: No data provided for chart"
- Invalid type: "❌ Error: Unsupported chart type 'xyz'. Use: table, bar, line, pie"
- Import issues: "❌ Error: rich library not available for chart display"
Integration with Janito
When using Janito in chat mode, you can ask it to create visualizations:
User: Show me a chart of the quarterly sales data
Janito: I'll create a bar chart for you...
[Uses read_chart tool to display the visualization]
Best Practices
- Data Validation: Ensure your data is properly formatted JSON
- Appropriate Chart Types: Choose the right chart type for your data
- Titles: Always provide descriptive titles
- Dimensions: Adjust width/height for better readability
- Data Types: Use numeric values for bar, pie, and line charts