Claude Code के साथ Chart Libraries का उपयोग
Claude Code का उपयोग करके chart libraries के बारे में जानें। Practical code examples शामिल हैं।
Claude Code से Chart Libraries का उपयोग
Dashboards और report screens में graph display essential है। Recharts, Chart.js, D3.js जैसी कई libraries हैं, लेकिन Claude Code का उपयोग करके हर library की strengths leverage करते हुए chart components quickly बनाए जा सकते हैं।
Library Selection
> React app में charts display करना है।
> Line chart, bar chart, pie chart, area chart implement करो।
> Recharts use करो, responsive और dark mode support के साथ।
- Recharts: React native, declarative और simple
- Chart.js: Lightweight, wide chart support
- D3.js: Maximum flexibility, high learning cost
Recharts से विभिन्न Charts
// src/components/charts/SalesLineChart.tsx
import {
LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip,
Legend, ResponsiveContainer
} from 'recharts';
interface DataPoint {
date: string;
revenue: number;
orders: number;
}
export function SalesLineChart({ data }: { data: DataPoint[] }) {
return (
<div className="bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm">
<h3 className="text-lg font-semibold mb-4 dark:text-white">Sales Trend</h3>
<ResponsiveContainer width="100%" height={300}>
<LineChart data={data}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" />
<XAxis dataKey="date" stroke="#9CA3AF" />
<YAxis yAxisId="revenue" stroke="#3B82F6" />
<YAxis yAxisId="orders" orientation="right" stroke="#10B981" />
<Tooltip
contentStyle={{
backgroundColor: '#1F2937',
border: 'none',
borderRadius: '8px',
color: '#fff',
}}
/>
<Legend />
<Line yAxisId="revenue" type="monotone" dataKey="revenue" stroke="#3B82F6" name="Revenue" strokeWidth={2} dot={false} />
<Line yAxisId="orders" type="monotone" dataKey="orders" stroke="#10B981" name="Orders" strokeWidth={2} dot={false} />
</LineChart>
</ResponsiveContainer>
</div>
);
}
Bar Chart
// src/components/charts/CategoryBarChart.tsx
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Cell } from 'recharts';
const COLORS = ['#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6'];
interface CategoryData {
name: string;
value: number;
}
export function CategoryBarChart({ data }: { data: CategoryData[] }) {
return (
<div className="bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm">
<h3 className="text-lg font-semibold mb-4 dark:text-white">Category-wise Sales</h3>
<ResponsiveContainer width="100%" height={300}>
<BarChart data={data} layout="vertical">
<CartesianGrid strokeDasharray="3 3" horizontal={false} />
<XAxis type="number" />
<YAxis type="category" dataKey="name" width={100} />
<Tooltip />
<Bar dataKey="value" radius={[0, 4, 4, 0]}>
{data.map((_, index) => (
<Cell key={index} fill={COLORS[index % COLORS.length]} />
))}
</Bar>
</BarChart>
</ResponsiveContainer>
</div>
);
}
Pie Chart
// src/components/charts/DistributionPieChart.tsx
import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer, Legend } from 'recharts';
const COLORS = ['#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6', '#EC4899'];
interface SegmentData {
name: string;
value: number;
}
export function DistributionPieChart({ data, title }: { data: SegmentData[]; title: string }) {
const total = data.reduce((sum, d) => sum + d.value, 0);
return (
<div className="bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm">
<h3 className="text-lg font-semibold mb-4 dark:text-white">{title}</h3>
<ResponsiveContainer width="100%" height={300}>
<PieChart>
<Pie
data={data}
cx="50%"
cy="50%"
innerRadius={60}
outerRadius={100}
dataKey="value"
label={({ name, value }) => `${name} ${((value / total) * 100).toFixed(0)}%`}
>
{data.map((_, index) => (
<Cell key={index} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Tooltip formatter={(v: number) => `${v.toLocaleString()} (${((v / total) * 100).toFixed(1)}%)`} />
<Legend />
</PieChart>
</ResponsiveContainer>
</div>
);
}
Chart Dashboard Assembly
// src/app/dashboard/analytics/page.tsx
import { SalesLineChart } from '@/components/charts/SalesLineChart';
import { CategoryBarChart } from '@/components/charts/CategoryBarChart';
import { DistributionPieChart } from '@/components/charts/DistributionPieChart';
export default async function AnalyticsPage() {
const [salesData, categoryData, channelData] = await Promise.all([
fetchSalesData(),
fetchCategoryData(),
fetchChannelData(),
]);
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold dark:text-white">Analytics Dashboard</h1>
<SalesLineChart data={salesData} />
<div className="grid md:grid-cols-2 gap-6">
<CategoryBarChart data={categoryData} />
<DistributionPieChart data={channelData} title="Channel-wise Traffic" />
</div>
</div>
);
}
Related Articles
Data visualization overall के लिए Data Visualization Implementation देखें, dashboard construction के लिए Admin Dashboard Development देखें।
Recharts official documentation (recharts.org) पर API reference check कर सकते हैं।
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।