Overview
This component demonstrates:- Creating pie and bar charts using Chart.js
- Fetching data from backend APIs
- Exporting charts to PDF using html2canvas and jsPDF
- Speech feedback integration
- Responsive chart rendering
Component metadata
src/app/_modules/_Demos/_DemosFeatures/files-generation/chart/chart.component.ts:14-24
Dependencies
The component relies on these key libraries:Chart.js
Version: ^3.9.1Used for rendering interactive charts (pie and bar charts)
jsPDF
Version: ^2.5.1Generates PDF documents from chart visualizations
html2canvas
Version: ^1.4.1Captures HTML elements as images for PDF export
Properties
Signals
chart.component.ts:30-31
Chart properties
- Pie chart
- Bar chart
chart.component.ts:36-40Methods
SetPieChart()
Initializes and renders a pie chart with data from the backend.chart.component.ts:91-181
Process:
- Fetches CSV statistical data from backend
- Parses JSON response
- Builds chart labels, data, and background colors
- Creates Chart.js pie chart instance
SetBarChart()
Initializes and renders a bar chart with session count data.chart.component.ts:183-265
Process:
- Fetches log statistics from backend
- Parses JSON data
- Creates labels combining page names and IP values
- Renders bar chart with session count data
GetPDF()
Exports a chart to PDF format.P_fileName- Chart identifier ('[PIE CHART]'or'[BAR CHART]')
chart.component.ts:270-301
Lifecycle hooks
ngOnInit()
Initializes both charts on component load.chart.component.ts:81-86
Constructor
Registers Chart.js components and sets up reactive effects for speech feedback.chart.component.ts:54-79
Key initialization:
Template structure
The component uses Angular Material tabs to organize different chart types:chart.component.html:18-69
Each tab includes:
- Canvas element for chart rendering
- PDF generation button
- Status message display using signals
Usage example
Include the component in your module:Data flow
Related components
- File generation - PDF, CSV, and XLS generation
- Speech panel - Voice feedback integration