A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
Build a small sales dashboard in React: four stat cards, a Recharts line chart that disappears when its parent has no height, and an orders table that sorts with one boolean in state, all in a Tailwind grid.
What you will learn
- Build a stat card component with label, value and change props
- Draw a responsive line chart with Recharts and give its parent a real height
- Sort a table with one piece of state without changing the original array
- Lay out a dashboard with a responsive Tailwind grid
Before you start
- Tailwind CSS 4 in React
- React useState
Think about a car dashboard and what the driver really needs. The speedometer: one number, how fast right now, read in a glance. The trip graph: where things are heading, a trend. The trip log: the exact details of what happened.
A good web dashboard works the same way. One number, a trend, and the details. Show those three, and everything else is clutter. In this article you build a small sales dashboard from three pieces: a stat card, a line chart and a sortable table.

The data
All three pieces read from one sample file, data.ts:
export type Order = { id: number; customer: string; status: 'Paid' | 'Pending'; total: number }
export const monthly = [
{ month: 'Jan', revenue: 4200 },
{ month: 'Feb', revenue: 5100 },
{ month: 'Mar', revenue: 4800 },
{ month: 'Apr', revenue: 6200 },
{ month: 'May', revenue: 7400 },
{ month: 'Jun', revenue: 8100 },
]
export const orders: Order[] = [
{ id: 1, customer: 'Emma', status: 'Paid', total: 120 },
{ id: 2, customer: 'Jack', status: 'Pending', total: 85 },
{ id: 3, customer: 'Priya', status: 'Paid', total: 240 },
{ id: 4, customer: 'Lucas', status: 'Paid', total: 60 },
{ id: 5, customer: 'Sofia', status: 'Pending', total: 175 },
]
export const stats = [
{ label: 'Revenue', value: '$35.8k', change: '+12% this month' },
{ label: 'Orders', value: '482', change: '+8% this month' },
{ label: 'Customers', value: '1,240', change: '+5% this month' },
{ label: 'Avg. order', value: '$74', change: '+3% this month' },
]
Stat card: one glance
type Props = { label: string; value: string; change: string }
export default function StatCard({ label, value, change }: Props) {
return (
<div className="rounded-xl bg-white p-5 shadow">
<p className="text-sm text-slate-500">{label}</p>
<p className="mt-1 text-3xl font-bold">{value}</p>
<p className="mt-1 text-sm text-emerald-600">{change}</p>
</div>
)
}
The card takes three props, typed on the first line: label, value and change. The label is small grey text (text-sm text-slate-500) that says what the number is. The value is big and bold (text-3xl font-bold), and the eye lands there first. The change is small and green (text-emerald-600), so you see the direction. One card, one number.
Line chart with Recharts
For the chart we use Recharts, a popular chart library for React:
import {
Line,
LineChart,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from 'recharts'
import { monthly } from './data'
export default function RevenueChart() {
return (
<div className="h-56">
<ResponsiveContainer width="100%" height="100%">
<LineChart data={monthly}>
<XAxis dataKey="month" />
<YAxis />
<Tooltip />
<Line dataKey="revenue" stroke="#2563eb" strokeWidth={3} />
</LineChart>
</ResponsiveContainer>
</div>
)
}
The first thing inside is a div with h-56. That is the parent, with a fixed height. Inside it sits ResponsiveContainer at 100% width and height, so the chart fills that parent, wide or narrow. LineChart gets the monthly array. XAxis reads the month key, YAxis works out the numbers by itself, and Tooltip gives you a popup on hover for free. Finally Line draws the revenue key in blue with a thick stroke.
From data to drawing
You do not need to memorise every chart option, because AI can generate those. But you need this foundation so the code makes sense when you read it.
Break it: no height, no chart
This is a very common mistake. Remove the height from the parent:
// before
<div className="h-56">
// after
<div>

ResponsiveContainer says 100%. But 100% of what? The parent has no height, so the chart is zero pixels tall. All you see is the title. No error message, just an empty card. Put h-56 back and the chart is there again.
The rule: a chart that fills 100% needs a parent with a real height.
Table: sort with state
import { useState } from 'react'
import { orders } from './data'
export default function OrdersTable() {
const [desc, setDesc] = useState(true)
const sorted = [...orders].sort((a, b) => a.total - b.total)
const rows = desc ? sorted.reverse() : sorted
const toggle = () => setDesc(!desc)
return (
<table className="w-full text-left">
<thead className="text-sm text-slate-500">
<tr>
<th>Customer</th>
<th>Status</th>
<th onClick={toggle}>Total {desc ? 'â–¼' : 'â–²'}</th>
</tr>
</thead>
<tbody>
{rows.map((o) => (
<tr key={o.id} className="border-t border-slate-100">
<td className="py-2">{o.customer}</td>
<td>{o.status}</td>
<td>${o.total}</td>
</tr>
))}
</tbody>
</table>
)
}
Which way we sort is one piece of state, desc. It starts as true, so the highest total comes first.
[...orders] makes a copy, and the copy is sorted by total. Never sort the original array: sort changes the array in place, and that would change the data underneath. If desc is true, the copy is reversed.
The Total header is clickable. A click calls toggle, which flips desc, and React redraws the rows in the new order with the arrow turned around. Each row gets key={o.id} so React can tell the rows apart.

Put it together: a grid
import OrdersTable from './OrdersTable'
import RevenueChart from './RevenueChart'
import StatCard from './StatCard'
import { stats } from './data'
export default function App() {
return (
<main className="mx-auto max-w-5xl space-y-6 p-6">
<h1 className="text-2xl font-bold">Sales overview</h1>
<section className="grid grid-cols-2 gap-4 md:grid-cols-4">
{stats.map((s) => (
<StatCard key={s.label} {...s} />
))}
</section>
<section className="grid gap-4 md:grid-cols-5">
<div className="rounded-xl bg-white p-5 shadow md:col-span-3">
<h2 className="mb-3 font-semibold">Revenue by month</h2>
<RevenueChart />
</div>
<div className="rounded-xl bg-white p-5 shadow md:col-span-2">
<h2 className="mb-3 font-semibold">Recent orders</h2>
<OrdersTable />
</div>
</section>
</main>
)
}
The first row is a grid: two columns on a phone, four from the md breakpoint. The four stat cards come from one array with map, so a fifth card is just one more object in stats. The second row is a five-column grid: the chart takes three columns (md:col-span-3) and the table takes two. Each sits in a white card with a heading. Resize the window and it adapts.
Which block, and when?
| You want to show | Use |
|---|---|
| One number that matters | Stat card |
| How something changes over time | Line chart |
| A comparison of a few groups | Bar chart (same Recharts, bars instead of a line) |
| Exact values to scan and sort | Table |
Every block on a dashboard must earn its place. If nobody reads it, remove it.
Common mistakes
- A chart parent with no height. No error, no chart.
- Sorting the original array.
orders.sort(...)mutates the shared data. Copy first with[...orders]. - Using the index as the row key. After a sort, the index no longer points at the same order. Use the id.
- Too many blocks. One number, a trend, the details. The rest is clutter.
Recap
A stat card for one number, a chart for a trend, a table for the details, and a grid to hold them. We covered the foundations, and with AI you can generate the rest. Try it yourself: add a bar chart of orders per status to the second row and give it a col-span that fits.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
One Request, Two Answers: the Same Post as an HTML Page and as JSON
Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.
A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.
How a Web Page Works: HTML Tags, Elements and Attributes
A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.
Semantic HTML: header, nav, main, aside and footer as Page Landmarks
The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.
