Posted on Leave a comment

React Charts and Graphs with Recharts: Visualize Data Beautifully

by Vincy. Last modified on December 3rd, 2025.

Representing data in a chart view is a huge subject in Mathematics and Computer Science. If you have the skill to transform raw numbers into a chart view, it’s a brilliant representation that makes users understand any complex data quickly.

Learning to build a chart in React will elevate your UI and make your application feel truly professional.

This React example includes dashboard visualization to display the following chart view.

  1. Sales & revenue trend in the form of line chart.
  2. Product-wise performance using column chart.
  3. Browser distribution in pie chart.
  4. Area chart to visualize users’ active time.

It uses Recharts library to show the raw data in a graph or chart form, as shown below.

React Charts Graphs Recharts Data Visualization

Main React component containing chart components

The DataVisualization component manages React states and useEffect. It manages the separate state variables for each type of charts.

The React useEffect fetches the JSON data and set them to bind for the charts.

The chart UI are created as separate components and used in the dashboard wrapper.

src/components/DataVisualization.jsx

import { useState, useEffect } from "react";
import Header from "../components/Header";
import StatsCards from "../components/StatsCards";
import LineChartBox from "../components/LineChartBox";
import BarChartBox from "../components/BarChartBox";
import PieChartBox from "../components/PieChartBox";
import AreaChartBox from "../components/AreaChartBox";
import Footer from "../components/Footer"; const DataVisualization = () => { const [lineData, setLineData] = useState([]); const [barData, setBarData] = useState([]); const [pieData, setPieData] = useState([]); const [areaData, setAreaData] = useState([]); useEffect(() => { fetch("/data/dashboard.json") .then((res) => res.json()) .then((data) => { setLineData(data.lineData); setBarData(data.barData); setPieData(data.pieData); setAreaData(data.areaData); }) .catch((err) => console.error("Error loading data:", err)); }, []); return ( <div className="dashboard-wrapper"> <div className="dashboard-container"> <Header /> <StatsCards /> <div className="charts-grid"> <LineChartBox data={lineData} /> <BarChartBox data={barData} /> <PieChartBox data={pieData} /> <AreaChartBox data={areaData} /> </div> <Footer /> </div> </div> );
};
export default DataVisualization;

Chart visualization header with trending data cards

In this code, the chart components are created for rendering in a dashboard. Added to the chart representation, the dashboard shows cards to display trending data.

You can replace it with your applications progressive data in this cards. For demonstration purpose, they are all static data from the client-side. It’s a matter of minute to plug your dynamic data from the database.

react chart graph visualization header

src/components/Header.jsx

const Header = () => ( <header className="dashboard-header"> <h1>Data Visualization Dashboard</h1> <p>Beautiful charts and graphs powered by Recharts in React</p> </header>
);
export default Header;

react chart graph statscards

src/components/StatsCards.jsx

import { TrendingUp, BarChart3, Users, Activity } from "lucide-react";
const StatsCards = () => { const stats = [ { icon: <TrendingUp strokeWidth={1} />, label: "Total Sales", value: "$24,850", change: "+12.5%" }, { icon: <BarChart3 strokeWidth={1} />, label: "Revenue", value: "$48,200", change: "+8.2%" }, { icon: <Users strokeWidth={1} />, label: "Users", value: "12,543", change: "+23.1%" }, { icon: <Activity strokeWidth={1} />, label: "Growth", value: "34.8%", change: "+5.4%" }, ]; return ( <div className="stats-grid"> {stats.map((stat, index) => ( <div key={index} className="stat-card"> <div className="stat-top"> <span className="stat-icon">{stat.icon}</span> <span className="stat-change">{stat.change}</span> </div> <p className="stat-label">{stat.label}</p> <p className="stat-value">{stat.value}</p> </div> ))} </div> );
};
export default StatsCards;

Line chart to show the sales revenue graph

This script imports the Recharts component required for rendering a line chart. The following components are mostly required for all the charts.

  • XAxis, YAxis
  • Tooltip and Legend
  • CartisanGrid
  • ResponsiveContainer

The chart is rendered in a ResponsiveContainer block which support chart scaling based on the viewport size. The Tooltip and CartisanGrid will be shown on hovering the chart. The X,Y axis and chart legend are very usual part of the chart view.

The LineChart and Line components are exclusive to this type of chart. It accepts Recharts attributes to set the stroke width and color of the line graph.

react data visualization line chart

src/components/LineChartBox.jsx

import { LineChart, Line, XAxis, YAxis, Tooltip, CartesianGrid, Legend, ResponsiveContainer } from "recharts";
const LineChartBox = ({ data }) => ( <div className="chart-card"> <h2>Sales & Revenue Trend</h2> <ResponsiveContainer width="100%" height={300}> <LineChart data={data}> <CartesianGrid strokeDasharray="3 3" stroke="#475569" /> <XAxis stroke="#94a3b8" /> <YAxis stroke="#94a3b8" /> <Tooltip /> <Legend /> <Line type="monotone" dataKey="sales" stroke="#3b82f6" strokeWidth={1} /> <Line type="monotone" dataKey="revenue" stroke="#10b981" strokeWidth={1} /> </LineChart> </ResponsiveContainer> </div>
);
export default LineChartBox;

Bar chart fir showing performance graph

The BarChart and Bar component of the Recharts library are used in this script. The BarChart accepts chart data and Bar element requires the color specification to fill the column bar.

src/components/BarChartBox.jsx

import { BarChart, Bar, XAxis, YAxis, Tooltip, CartesianGrid, ResponsiveContainer } from "recharts";
const BarChartBox = ({ data }) => ( <div className="chart-card"> <h2>Product Performance</h2> <ResponsiveContainer width="100%" height={300}> <BarChart data={data}> <CartesianGrid strokeDasharray="3 3" stroke="#475569" /> <XAxis dataKey="category" stroke="#94a3b8" /> <YAxis stroke="#94a3b8" /> <Tooltip /> <Bar dataKey="value" fill="#8b5cf6" /> </BarChart> </ResponsiveContainer> </div>
);
export default BarChartBox;

Pie chart – Recharts – showing browser distribution

This Recharts component accepts the inner-radius, outer-radius, cy, cx properties to draw the pie chart.

This chart type will have a Pie component which is to draw the pie wedges in the wrapper. The Cell is to draw each pie slices.

It receives the data and datakey in the <Pie /> component of this Recharts library.

react data visualization pie chart

src/components/PieChartBox.jsx

import { PieChart, Pie, Tooltip, ResponsiveContainer, Cell } from "recharts";
const PieChartBox = ({ data }) => ( <div className="chart-card"> <h2>Browser Distribution</h2> <ResponsiveContainer width="100%" height={300}> <PieChart> <Pie data={data} dataKey="value" innerRadius={60} outerRadius={100} paddingAngle={2} cx="50%" cy="50%" > {data.map((entry, i) => ( <Cell key={i} fill={entry.color} /> ))} </Pie> <Tooltip /> </PieChart> </ResponsiveContainer> <div className="pie-legend"> {data.map((item, i) => ( <div key={i} className="legend-item"> <span className="legend-color" style={{ background: item.color }} /> <span>{item.name}: {item.value}%</span> </div> ))} </div> </div>
);
export default PieChartBox;

Area chart using the Recharts library

In this graph, it shows the active users count by time. It represents how many users are actively using your app at a particular point of time. It will help to monitor the spikes and drop in the traffic, product or services usages and more.

The AreaChart is the wrapper that contains the Area element which is to show the shaded part of the chart as shown below.

The JSON data contains the time and user count for each level of the graph. The area is highlighted within a LinearGadient definition.

react data visualization area chart

src/components/AreaChartBox.jsx

import { AreaChart, Area, XAxis, YAxis, Tooltip, CartesianGrid, ResponsiveContainer } from "recharts";
const AreaChartBox = ({ data }) => ( <div className="chart-card"> <h2>Active Users Over Time</h2> <ResponsiveContainer width="100%" height={300}> <AreaChart data={data}> <defs> <linearGradient id="colorUsers" x1="0" y1="0" x2="0" y2="1"> <stop offset="5%" stopColor="#f59e0b" stopOpacity={0.8} /> <stop offset="95%" stopColor="#f59e0b" stopOpacity={0} /> </linearGradient> </defs> <CartesianGrid strokeDasharray="3 3" stroke="#475569" /> <XAxis dataKey="time" stroke="#94a3b8" /> <YAxis stroke="#94a3b8" /> <Tooltip /> <Area type="monotone" dataKey="users" stroke="#f59e0b" fill="url(#colorUsers)" /> </AreaChart> </ResponsiveContainer> </div>
);
export default AreaChartBox;

react chart graph data visualization

Conclusion

The React charts provide graphical view to understand your trending data. The line chart plots the performance range over time, the pie chart slices down browser distribution at a quick view, and the area chart visualizes the user activity patterns. By using Recharts responsive wrapper, each graph fit for different screen size. Overall, these charts transform raw numbers into visual stories to help efficient decision making.

References:

  1. Recharts library documentation
  2. Best chart libraries for React

Download

Vincy
Written by Vincy, a web developer with 15+ years of experience and a Masters degree in Computer Science. She specializes in building modern, lightweight websites using PHP, JavaScript, React, and related technologies. Phppot helps you in mastering web development through over a decade of publishing quality tutorials.

↑ Back to Top

Posted on Leave a comment

PHP 8.5.0 Released

The PHP development team announces the immediate availability of PHP 8.5.0.
This release marks the latest major release of the PHP language. PHP 8.5 comes with numerous improvements and new features such as:
- New URI extension
- New pipe operator (|>)
- Clone With
- New #[\NoDiscard] attribute
- Support for closures, casts, and first class callables in constant
expressions
- And much much more... For source downloads of PHP 8.5.0 please visit our downloads page.
Windows binaries can be found on the PHP for Windows site.
The list of changes is recorded in the ChangeLog. Release Announcement: <https://php.net/releases/8_5_0.php>
Downloads: <https://php.net/downloads>
Windows downloads: <https://windows.php.net/download#php-8.5>
Changelog: <https://php.net/ChangeLog-8.php#8.5.0>
Release Manifest: <
https://gist.github.com/DanielEScherzer/95b23360da074750e3910a6b37632675> Many thanks to all the contributors and supporters! Daniel Scherzer, Volker Dusch, and Pierrick Charron php-8.5.0.tar.bz2
SHA256 hash:
cd16cb045b34a6cec6a83008e1b335f365c7a832fcc483df82308664c6d021f9
PGP signature:
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE2VwDvHAr6VFTRK4zdORLyQZ3AaUFAmkcLKgACgkQdORLyQZ3
AaVWqw/+KgvBpXkmuW9vvqq2coYgNCMxizyZiP4T2usdHEM0fQkYc30sd20if2HZ
nQOzOPhJCJiGyApWQtEikSV2YKPMjcGY05Y4JOuy0F4sqBlKHkndcg8QEwhf8Zqd
pHwIpd/LkAOvT7Mcb8tFwLepnAtxaPvvdqIpVECeX2ceRskiFEHWMxSaHQosNaU6
Yemc8ThB2MA02q1cG8P2KviRcQ7eLymenNv5f0Lyi4js4nF3JIgMDl14byPF7fyu
jGQdyWAxbkB4CEsUuKXvDK3THRonZAUOHxfDaL2VfHfKpg3D8G2ZJ6A9asyue994
9vJY5b9bxKt9lXm+HmwEsNdBEbDDyDJ0bP7M0FQBvk0jIqP1GS3jjMYxXCEj0w3a
JlCmEK544KhkTsZbn0U++azQJbRBQz57IBzRgrTRdQRdZTrzHCyJVnr5iK8zxtQj
/JhVHSYfxCC481KTx79p3D1lJYxVPsEUXyJmiwfzS8iy6WvetqLBnteWfRqmBnqd
q5LCDYiTpsQXqKw3MhG3tZ90vxbXDGn425E9RrNRPBs1INfNzUrzpuAgh6EGFm0j
mo85KUSaBo9/D8CGI4gHiR4cy6TWIvMUujPL7gND4BDMB4wAfs0gWg9Mw6KFbost
oXOwFJfgkMzQlAd0wkuYJxla3daQD9vpSJGBWNahU99qLvJGWAQ=
=N7Fg
-----END PGP SIGNATURE----- php-8.5.0.tar.gz
SHA256 hash:
dc3651369c9b63320dd4ea8e272c6a23f18e50f67c13d10ee368c86961dbd10f
PGP signature:
-----BEGIN PGP SIGNATURE----- iQIz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6mMm7K1bRyc4L+cU
rFAk8h6lwGS+vgmrFFAfas1nUWahj1i9GbiI+fM0f/GGm8FO1MzYbDo79fLe9fto
NmNPo7G97DF6YQx6K3W3FpEU4D1mTpfs6yIVIex6PBnRLDi5oikhpPAH7TKDwzfV
5zyXwBYbt6Vasuy56FwYYJpdSs0j0WVFqjBB6m3LA7qAZccOPNshdStirjOqppW6
UXJSE647kYmzW8no9G/yiY6FUWclgWxX0Inc1w9Z4rIY7PaUxJCZTHpzCpVj+9qG
76culXXNNmM7MweY8CGX+jT56hbv7jfSpMv2xnJIojRMc3rfyEBYswxmRWbt7Hmx
6Wf3MG3hTPNt/CihAGNqBAi95ApI/JXHVcXAbzdBH6pl9j72bVKFi5MsmXjpCjQU
+qY0Y+J9iNCYtlRTKmJ02OQBkDHvwo1ogPjLvIKTiEPbTUTPuIROxTChGm9RfLR/
SMBOX1Owd4IW9APiHq6W+LlXCPwYp/MdwxoHR2nYGVtoXnRwcBc2uYDP8QnUO1tz
xBdv96iJPC1vNbFazB3UxUEGWVj/SQ2R+qiW71q59otS4lTZjJc=
=qZeT
-----END PGP SIGNATURE-----

Thread (1 message)

  • Pierrick Charron
Posted on Leave a comment

PHP 8.4.15 Released

The PHP development team announces the immediate availability of PHP
8.4.15. This is a bugfix release. All PHP 8.4 users are encouraged to upgrade to this version. For source downloads of PHP 8.4.15 please visit our downloads page.
Windows binaries can be found on the PHP for Windows site.
The list of changes is recorded in the ChangeLog. Release Announcement: <https://php.net/releases/8_4_15.php>
Downloads: <https://php.net/downloads>
Windows downloads: <https://windows.php.net/download#php-8.4>
Changelog: <https://php.net/ChangeLog-8.php#8.4.15>
Release Manifest: <https://gist.github.com/NattyNarwhal/c54102da652aca9c85b03b531b78989f> Many thanks to all the contributors and supporters! Regards,
Calvin Buckley, Saki Takamachi, and Eric Mann php-8.4.15.tar.bz2
SHA256 hash: b7155bdd498d60d63e4bc320dc224863976d31b5bd9339699726c961255a3197
PGP signature:
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSdf5mgy48FyKaVjWJWqXr3YAo5pgUCaRy0twAKCRBWqXr3YAo5
pi90AQC3EOfR5tGKZu8LsVw0UjRYV7veiwez5g2X5DYrSauRnwD+P9rb4L5gjVRu
oayIL2INpN0UK/QIlhLPZCN1ogFVjwQ=
=tG6q
-----END PGP SIGNATURE----- php-8.4.15.tar.gz
SHA256 hash: 51d23c98073c1e88c98c12b175736a11316cd3d4753f8d060934e53e5a9945c3
PGP signature:
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSdf5mgy48FyKaVjWJWqXr3YAo5pgUCaRy0uwAKCRBWqXr3YAo5
pvcIAP940m3vt0DxVv1LapKrMGVYOAc7Ic3C3stmOVZCdx24JQD7BS+VPuf6cbGs
araJ+uvTrvEDVPUP9w6aJ2eAmJzkIgI=
=C1of
-----END PGP SIGNATURE----- php-8.4.15.tar.xz
SHA256 hash: a060684f614b8344f9b34c334b6ba8db1177555997edb5b1aceab0a4b807da7e
PGP signature:
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSdf5mgy48FyKaVjWJWqXr3YAo5pgUCaRy0uwAKCRBWqXr3YAo5
pruxAQCLpuOP2rHPfFZKwqt98fT5Yug6ID91a5/nJ6rZpWUdGgD/UKj4vdmOnJfH
oyHTFF0fOpdWh4TxA2Zr3aD8xKATmQA=
=5beQ
-----END PGP SIGNATURE-----

Thread (1 message)

  • Calvin Buckley