import React from 'react'; import { DailyStat } from '../../types'; interface BarChartProps { data: DailyStat[]; } const BarChart: React.FC = ({ data }) => { const chartHeight = 150; const barWidth = 30; const barMargin = 15; const chartWidth = data.length * (barWidth + barMargin); const getDayLabel = (dateString: string) => { const date = new Date(dateString); const userTimezoneOffset = date.getTimezoneOffset() * 60000; const adjustedDate = new Date(date.getTime() + userTimezoneOffset); return adjustedDate.toLocaleDateString('en-US', { weekday: 'short' }); }; return (
Weekly Medication Adherence Chart {/* Y-Axis Labels */} 100% 50% 0% {/* Y-Axis Grid Lines */} {data.map((item, index) => { const x = index * (barWidth + barMargin); const barHeight = (item.adherence / 100) * (chartHeight - 10); const y = chartHeight - barHeight; const barColorClass = item.adherence >= 90 ? 'fill-current text-green-500 dark:text-green-400' : item.adherence >= 70 ? 'fill-current text-amber-500 dark:text-amber-400' : 'fill-current text-red-500 dark:text-red-400'; return ( {getDayLabel(item.date)}: {item.adherence}% adherence {getDayLabel(item.date)} ); })}
); }; export default BarChart;