import React from 'react'; import { motion } from 'framer-motion'; import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, } from 'chart.js'; import { Bar, Doughnut } from 'react-chartjs-2'; ChartJS.register( CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement ); const FreshnessChart = ({ data }) => { const barData = { labels: data.labels, datasets: [ { label: 'Freshness %', data: data.freshness, backgroundColor: [ 'rgba(59, 130, 246, 0.8)', 'rgba(245, 158, 11, 0.8)', 'rgba(239, 68, 68, 0.8)', ], borderColor: [ 'rgba(59, 130, 246, 1)', 'rgba(245, 158, 11, 1)', 'rgba(239, 68, 68, 1)', ], borderWidth: 2, borderRadius: 8, }, ], }; const doughnutData = { labels: data.labels, datasets: [ { data: data.days_left, backgroundColor: [ 'rgba(59, 130, 246, 0.8)', 'rgba(245, 158, 11, 0.8)', 'rgba(239, 68, 68, 0.8)', ], borderColor: [ 'rgba(59, 130, 246, 1)', 'rgba(245, 158, 11, 1)', 'rgba(239, 68, 68, 1)', ], borderWidth: 2, }, ], }; const barOptions = { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false, }, tooltip: { backgroundColor: 'rgba(15, 23, 42, 0.9)', titleColor: '#fff', bodyColor: '#94a3b8', borderColor: 'rgba(255, 255, 255, 0.1)', borderWidth: 1, padding: 12, cornerRadius: 8, callbacks: { label: (context) => `Freshness: ${context.raw}%` } }, }, scales: { x: { grid: { display: false, }, ticks: { color: '#94a3b8', font: { size: 11, }, }, }, y: { beginAtZero: true, max: 100, grid: { color: 'rgba(148, 163, 184, 0.1)', }, ticks: { color: '#94a3b8', font: { size: 11, }, callback: (value) => `${value}%`, }, }, }, }; const doughnutOptions = { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom', labels: { color: '#94a3b8', padding: 15, font: { size: 11, }, usePointStyle: true, }, }, tooltip: { backgroundColor: 'rgba(15, 23, 42, 0.9)', titleColor: '#fff', bodyColor: '#94a3b8', borderColor: 'rgba(255, 255, 255, 0.1)', borderWidth: 1, padding: 12, cornerRadius: 8, callbacks: { label: (context) => `${context.label}: ${context.raw} days left` } }, }, cutout: '60%', }; return (

Storage Comparison

Freshness by storage condition

{/* Bar Chart */}

Freshness Level (%)

{/* Doughnut Chart */}

Days Remaining

{/* Legend */}
Ideal (Refrigerated)
Room Temperature
High Humidity
); }; export default FreshnessChart;