Chart Visualization Feature
Overview
The DataTruth application now includes interactive chart visualization for query results. Users can toggle between table and chart views to better understand their data through visual representations.
Features
View Toggle
- Table View: Traditional tabular display of query results
- Chart View: Visual representation using interactive charts
- Easy toggle between views with dedicated buttons
Supported Chart Types
1. Bar Chart
- Best for: Comparing values across categories
- Use case: Sales by region, counts by department, etc.
- Features: Color-coded bars, grid lines, tooltips
2. Line Chart
- Best for: Time series data, trends over time
- Use case: Daily revenue, monthly growth, etc.
- Features: Smooth lines, data points, trend visualization
3. Pie Chart
- Best for: Part-to-whole relationships
- Use case: Market share, percentage breakdowns
- Features: Percentage labels, legend, top 8 categories
Smart Chart Selection
The DataChart component automatically analyzes your data structure to:
- Identify numeric columns (for Y-axis values)
- Identify categorical columns (for X-axis labels)
- Suggest the most appropriate chart type
- Handle edge cases (no numeric data, single values, etc.)
Data Requirements
For optimal chart visualization:
- Minimum: At least one numeric column
- Recommended: Mix of categorical and numeric columns
- Limit: Charts display up to 20 data points (to prevent overcrowding)
Features
- Automatic Type Detection: The component intelligently detects column types
- Multiple Metrics: Can visualize multiple numeric columns simultaneously
- Interactive Tooltips: Hover over data points for detailed information
- Responsive Design: Charts adapt to container width
- Color Palette: Professional color scheme with 8 distinct colors
Usage
Basic Query Example
-- This query will display well as a bar chart
SELECT
agent_name,
COUNT(*) as total_calls,
AVG(call_duration) as avg_duration
FROM calls
GROUP BY agent_name
ORDER BY total_calls DESC
LIMIT 10;
Time Series Example
-- This query is perfect for line charts
SELECT
DATE(call_timestamp) as date,
COUNT(*) as call_count,
AVG(call_duration) as avg_duration
FROM calls
WHERE call_timestamp >= DATE('now', '-30 days')
GROUP BY DATE(call_timestamp)
ORDER BY date;
Percentage Example
-- This works well with pie charts
SELECT
call_status,
COUNT(*) as count
FROM calls
GROUP BY call_status;
User Interface
Toggle Buttons
Located above the data display:
- Table Button: Shows grid icon, switches to tabular view
- Chart Button: Shows bar chart icon, switches to chart view
- Active button is highlighted with white background
Chart Type Selector
Within chart view, choose from:
- Bar Chart (vertical bars)
- Line Chart (connected data points)
- Pie Chart (circular segments)
Technical Details
Dependencies
- Recharts: React charting library
- Version: Latest (installed via npm)
- Components: BarChart, LineChart, PieChart
- Features: Responsive, animated, customizable
Component Structure
ChatMessage
├── View Toggle (Table/Chart)
└── Conditional Display
├── Table View → DataTable component
└── Chart View → DataChart component
├── Chart Type Selector
└── Responsive Chart Container
├── BarChart
├── LineChart
└── PieChart
Data Transformation
The DataChart component:
- Receives raw query results as array of objects
- Analyzes column types (string vs numeric)
- Transforms data into chart-friendly format
- Selects appropriate X-axis (categorical) and Y-axis (numeric) columns
- Limits to top 20 records for performance
- Renders selected chart type with styling
Edge Cases Handled
- No Data: Shows “No data to visualize” message
- No Numeric Columns: Shows warning with explanation
- Single Row: Displays as single bar in chart
- Too Many Categories: Limits to top 20, shows note
- Missing Values: Filters out null/undefined values
- Mixed Data Types: Intelligently categorizes columns
Best Practices
For Users
- Start with Table View: Understand data structure first
- Choose Appropriate Queries: Group and aggregate for better charts
- Limit Results: Use LIMIT clause for cleaner visualizations
- Use Meaningful Labels: Column names appear in charts
- Experiment with Chart Types: Different charts reveal different insights
For Developers
- Data Preparation: Ensure clean data from SQL queries
- Performance: Limit data points displayed (current: 20)
- Accessibility: Maintain color contrast, provide tooltips
- Error Handling: Graceful degradation for unsupported data
- Testing: Test with various query result structures
Troubleshooting
“No numeric data found” Error
Problem: All columns in query results are text/string type
Solution: Include numeric columns in your query:
-- Instead of:
SELECT customer_name, order_date FROM orders;
-- Use:
SELECT customer_name, COUNT(*) as order_count FROM orders GROUP BY customer_name;
Chart Shows Only a Few Items
Reason: Chart displays top 20 items to prevent overcrowding
Solution:
- Use more specific WHERE clauses
- Apply better filtering in SQL
- Use LIMIT clause strategically
Colors Look Similar
Reason: More than 8 data series (exceeds color palette)
Solution: Reduce number of metrics or categories:
-- Instead of multiple metrics:
SELECT category, metric1, metric2, metric3, ... FROM table;
-- Use separate queries:
SELECT category, metric1 FROM table;
Future Enhancements
Planned features:
- Additional Chart Types: Scatter, area, radar charts
- Chart Customization: User-selectable colors, labels
- Export Options: Download as PNG, SVG, or data
- Drill-Down: Click chart elements to filter data
- Comparison Mode: Side-by-side chart comparisons
- Annotations: Add notes and markers to charts
- Real-time Updates: Live data refresh in charts
Examples Gallery
Example 1: Sales by Region (Bar Chart)
SELECT region, SUM(amount) as total_sales
FROM transactions
GROUP BY region
ORDER BY total_sales DESC;
→ Shows regions on X-axis, sales on Y-axis as colored bars
Example 2: Monthly Trend (Line Chart)
SELECT
strftime('%Y-%m', date) as month,
SUM(revenue) as monthly_revenue
FROM sales
GROUP BY month
ORDER BY month;
→ Shows time progression with connected data points
Example 3: Call Status Distribution (Pie Chart)
SELECT status, COUNT(*) as count
FROM calls
GROUP BY status;
→ Shows percentage breakdown of call statuses
Conclusion
The chart visualization feature transforms DataTruth from a query tool into a complete analytics platform. By making data more visual and interactive, users can:
- Identify trends faster
- Spot anomalies easily
- Communicate insights better
- Make data-driven decisions confidently
For questions or feedback, please refer to the main documentation or submit an issue.