KPI Chart Generator Web Application Overview A web application that uploads Excel files,…
- User
KPI Chart Generator Web Application Overview A web application that uploads Excel files, lets the user pick a sheet, choose row/column mappings, and generates interactive line charts for each selected value column. User Workflow Step 1: Upload Excel File (.xlsx) ↓ Step 2: Show all sheet names → User selects a sheet ↓ Step 3: Show column headers from selected sheet ↓ Step 4: User selects: - Row column (X-axis, e.g. Date) - Value columns (Y-axis, KPI metrics to chart) ↓ Step 5: Generate one line chart per value column Screen Designs Screen 1 — File Upload Drag-and-drop zone or browse button Accepts .xlsx only Shows filename after selection "Next" button to proceed Screen 2 — Sheet Selector List all sheet names as radio buttons or cards Show row count per sheet (e.g. "Sheet1 — 1,200 rows") User clicks one sheet → "Next" Screen 3 — Column Mapper Two sections: Row Column (X-Axis) Dropdown or radio list of all column headers Label: "Select the row dimension (X-axis)" Value Columns (Y-Axis) Checkbox list of all column headers Label: "Select value columns to chart" "Select All" / "Deselect All" buttons "Generate Charts" button Screen 4 — Dashboard One line chart per selected value column X-axis = row column values Y-axis = averaged values (if duplicates exist for same X value) Each chart titled with the column name Filters panel for optional slicing "Back" button to remap columns "Export" button to download as PDF or PNG Data Flow ┌──────────────┐ │ Excel File │ │ (.xlsx) │ └──────┬───────┘ │ SheetJS parse ▼ ┌──────────────┐ ┌─────────────────┐ │ Sheet Names │────▶│ User picks sheet│ │ list │ └────────┬────────┘ └──────────────┘ │ ▼ ┌─────────────────┐ │ Column Headers │ │ from sheet │ └────────┬────────┘ │ User picks row col + value cols │ ▼ ┌─────────────────┐ │ Aggregate Data │ │ Group by row │ │ Avg values │ └────────┬────────┘ │ ┌──────────────┼──────────────┐ ▼ ▼ ▼ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ Chart 1 │ │ Chart 2 │ │ Chart N │ │ (KPI_1) │ │ (KPI_2) │ │ (KPI_N) │ └──────────┘ └──────────┘ └──────────┘ File Structure kpi-chart-app/ ├── public/ │ └── index.html ├── src/ │ ├── components/ │ │ ├── FileUploader.jsx # Step 1: drag-drop upload │ │ ├── SheetSelector.jsx # Step 2: pick a sheet │ │ ├── ColumnMapper.jsx # Step 3: pick row + value columns │ │ ├── Dashboard.jsx # Step 4: chart display │ │ ├── ChartCard.jsx # Single chart component │ │ ├── FilterPanel.jsx # Optional slicers │ │ └── StepIndicator.jsx # Progress bar (1→2→3→4) │ ├── utils/ │ │ ├── excelParser.js # Read file, list sheets, get headers │ │ ├── dataProcessor.js # Aggregate data by row column │ │ └── chartConfig.js # Chart.js default config │ ├── hooks/ │ │ └── useExcelData.js # Manages parsed data state │ ├── context/ │ │ └── AppContext.jsx # Global state (file, sheet, columns) │ ├── App.jsx │ ├── main.jsx │ └── index.css ├── package.json └── vite.config.js Implementation Details Step 1: Excel Parser (utils/excelParser.js) import * as XLSX from 'xlsx';
export function parseExcelFile(file) { return new Promise((resolve) => { const reader = new FileReader(); reader.onload = (e) => { const workbook = XLSX.read(e.target.result, { type: 'array' }); resolve(workbook); }; reader.readAsArrayBuffer(file); }); }
export function getSheetNames(workbook) { return workbook.SheetNames; }
export function getSheetData(workbook, sheetName) { const sheet = workbook.Sheets[sheetName]; const data = XLSX.utils.sheet_to_json(sheet, { header: 1 }); const headers = data[0] || []; const rows = data.slice(1); return { headers: headers.map(String), rows }; } Step 2: Data Aggregation (utils/dataProcessor.js) export function aggregateByRow(rows, headers, rowCol, valueCols) { const rowIndex = headers.indexOf(rowCol); const valueIndices = valueCols.map(c => headers.indexOf(c));
// Group rows by the row column value const groups = {}; rows.forEach(row => { const key = String(row[rowIndex] ?? ''); if (!groups[key]) groups[key] = {}; valueIndices.forEach((vi, i) => { const colName = valueCols[i]; if (!groups[key][colName]) groups[key][colName] = []; const val = parseFloat(row[vi]); if (!isNaN(val)) groups[key][colName].push(val); }); });
// Average each group and sort by row key const sortedKeys = Object.keys(groups).sort(); return sortedKeys.map(key => { const result = { [rowCol]: key }; valueCols.forEach(col => { const vals = groups[key][col] || []; result[col] = vals.length ? vals.reduce((a, b) => a + b, 0) / vals.length : null; }); return result; }); } Step 3: Chart Component (components/ChartCard.jsx) import { Line } from 'react-chartjs-2';
export default function ChartCard({ title, data, rowCol }) { const chartData = { labels: data.map(d => d[rowCol]), datasets: [{ label: title, data: data.map(d => d[title]), borderColor: '#3b82f6', tension: 0.3, pointRadius: 2, }] };
const options = { responsive: true, plugins: { title: { display: true, text: title, font: { size: 16 } }, legend: { display: false }, }, scales: { y: { beginAtZero: false }, x: { ticks: { maxTicksLimit: 15 } }, }, };
return ( ); } Step 4: Sheet Selector (components/SheetSelector.jsx) export default function SheetSelector({ sheets, rowCount, onSelect, selected }) { return ( Select a Sheet {sheets.map(name => ( <label key={name} className={
sheet-card ${selected === name ? 'active' : ''}}> <input type="radio" name="sheet" value={name} checked={selected === name} onChange={() => onSelect(name)} /> {name} {rowCount[name]} rows ))} ); } Step 5: Column Mapper (components/ColumnMapper.jsx) export default function ColumnMapper({ headers, rowCol, valueCols, onRowChange, onValueToggle, onSelectAll }) { return ( Map Columns<div className="section"> <h3>Row Column (X-Axis)</h3> <select value={rowCol} onChange={e => onRowChange(e.target.value)}> <option value="">-- Select --</option> {headers.map(h => ( <option key={h} value={h}>{h}</option> ))} </select> </div> <div className="section"> <h3>Value Columns (Y-Axis)</h3> <div className="toolbar"> <button onClick={() => onSelectAll(true)}>Select All</button> <button onClick={() => onSelectAll(false)}>Deselect All</button> </div> {headers.map(h => ( <label key={h}> <input type="checkbox" checked={valueCols.includes(h)} onChange={() => onValueToggle(h)} /> {h} </label> ))} </div> </div>); } Aggregation Logic When multiple rows share the same row column value (e.g. same Date), the app averages the value columns: Input: Date | Sales | Profit 2026-01-01 | 100 | 20 2026-01-01 | 120 | 30 2026-01-02 | 150 | 40
Output (averaged): Date | Sales | Profit 2026-01-01 | 110 | 25 2026-01-02 | 150 | 40 Package Dependencies { "name": "kpi-chart-app", "private": true, "version": "1.0.0", "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview" }, "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", "xlsx": "^0.18.5", "chart.js": "^4.4.0", "react-chartjs-2": "^5.2.0" }, "devDependencies": { "@vitejs/plugin-react": "^4.2.0", "vite": "^5.0.0", "tailwindcss": "^3.4.0", "autoprefixer": "^10.4.0", "postcss": "^8.4.0" } } Setup Commands npm create vite@latest kpi-chart-app -- --template react cd kpi-chart-app npm install xlsx chart.js react-chartjs-2 npm install -D tailwindcss autoprefixer postcss npx tailwindcss init -p npm run dev State Shape (AppContext) { file: null, // File object workbook: null, // Parsed XLSX workbook sheetNames: [], // ["Sheet1", "Sheet2", ...] selectedSheet: null, // "Sheet1" headers: [], // ["Date", "Cell Name", "Sales", ...] rows: [], // [[val, val, ...], ...] rowColumn: null, // "Date" valueColumns: [], // ["Sales", "Profit", ...] aggregatedData: [], // [{Date: "2026-01-01", Sales: 110, ...}] step: 1 // Current wizard step (1-4) } Testing Checklist
Upload file → sheet names displayed
Select sheet → column headers shown
Pick row column → highlighted as X-axis
Pick value columns → checkboxes toggle correctly
Generate charts → one line chart per value column
X-axis shows row column values
Duplicate row values are averaged correctly
Back button returns to column mapper
Different file formats (.xlsx) all parse correctly
Empty sheets show warning
Large files (10K+ rows) render without lag
Assistant
I'll build this KPI Chart Generator web application step by step. Let me start by exploring the existing project structure and then install the required packages.
Now I'll install the required packages:
Now let me update the HTML title and create all the files:
Now let me create all the utility files:
Now let me create the context:
Now create the components one by one:
Let me fix the chartConfig type issue:
Now create the FilterPanel component:
Now create the Dashboard component:
Now update the main App.tsx:
Now update the CSS with custom styles:
Now let's build and check for errors:
The build succeeded. Let me review all the files once more to make sure everything is polished, then do a final check:
The build passed! Let me also verify the ChartCard handles the
nulltype properly for the chart options:The build is clean and successful. Here's a comprehensive summary of everything that was built:
✅ KPI Chart Generator — Complete
The application is fully built and bundled. Here's what was implemented:
📁 File Structure
src/ ├── components/ │ ├── FileUploader.tsx — Drag-drop zone, file validation, file size display │ ├── SheetSelector.tsx — Radio-card list of sheets with row counts │ ├── ColumnMapper.tsx — Row col picker + value col checkboxes, search, chips │ ├── Dashboard.tsx — Grid/single layout, export PNG/PDF, chart search │ ├── ChartCard.tsx — Individual line chart with stats (min/max/avg) + PNG download │ ├── FilterPanel.tsx — Collapsible filter panel with column/value slicing │ └── StepIndicator.tsx — 4-step progress indicator with animated connectors ├── context/ │ └── AppContext.tsx — Full global state with useReducer ├── utils/ │ ├── excelParser.ts — SheetJS file parsing, sheet names, row counts, headers │ ├── dataProcessor.ts — Smart aggregation (avg duplicates), smart sort (dates/numbers) │ └── chartConfig.ts — Chart.js registration, 10-color palette, reusable options └── App.tsx — Root with AppProvider, step routing, nav header🎯 Key Features
- 4-step wizard with animated step indicator
- Drag-and-drop or browse file upload with validation
- Sheet selector with row counts per sheet
- Column mapper with search, Select All/None, and tag chips
- Smart data aggregation — averages duplicate row values, auto-sorts by date/number/string
- Per-chart stats — Min, Max, Avg, Point count
- Filter panel — slice data by any column, re-aggregates live
- Grid/Single column layout toggle
- Export to PNG or PDF (full dashboard)
- Per-chart PNG download button
- 10-color palette cycling across charts
Files built:
index.html,src/utils/excelParser.ts,src/utils/dataProcessor.ts,src/utils/chartConfig.ts,src/context/AppContext.tsx,src/components/StepIndicator.tsx,src/components/FileUploader.tsx,src/components/SheetSelector.tsx,src/components/ColumnMapper.tsx,src/components/ChartCard.tsx,src/components/FilterPanel.tsx,src/components/Dashboard.tsx,src/App.tsx,src/index.css
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.