diff --git a/components/AsalDaerahChart.tsx b/components/AsalDaerahChart.tsx index 249183c..6215523 100644 --- a/components/AsalDaerahChart.tsx +++ b/components/AsalDaerahChart.tsx @@ -92,7 +92,6 @@ export default function AsalDaerahChart() { }, maxWidth: 200, }, - tickAmount: undefined, }, fill: { opacity: 1, diff --git a/components/JenisPendaftaranBeasiswaChart.tsx b/components/JenisPendaftaranBeasiswaChart.tsx index 3e15d91..fce9a14 100644 --- a/components/JenisPendaftaranBeasiswaChart.tsx +++ b/components/JenisPendaftaranBeasiswaChart.tsx @@ -162,7 +162,8 @@ export default function JenisPendaftaranBeasiswaChart({ selectedYear, selectedJe axisBorder: { show: true, color: theme === 'dark' ? '#374151' : '#E5E7EB' - } + }, + tickAmount: 5, }, fill: { opacity: 1 @@ -203,23 +204,6 @@ export default function JenisPendaftaranBeasiswaChart({ selectedYear, selectedJe const series = processSeriesData(); - // Calculate the maximum value from all series for y-axis padding - const maxValue = Math.max( - ...series.flatMap(s => s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -268,7 +252,7 @@ export default function JenisPendaftaranBeasiswaChart({ selectedYear, selectedJe
{typeof window !== 'undefined' && series.length > 0 && ( series.data) - ); - - // Add 20% padding to the maximum value - const xAxisMax = Math.ceil(maxValue * 1.1); setOptions(prev => ({ ...prev, xaxis: { ...prev.xaxis, categories: tahunAngkatan, - max: xAxisMax }, })); } catch (err) { diff --git a/components/JenisPendaftaranLulusChart.tsx b/components/JenisPendaftaranLulusChart.tsx index 5840962..c0d64c7 100644 --- a/components/JenisPendaftaranLulusChart.tsx +++ b/components/JenisPendaftaranLulusChart.tsx @@ -159,7 +159,8 @@ export default function JenisPendaftaranLulusChart({ selectedYear }: Props) { axisBorder: { show: true, color: theme === 'dark' ? '#374151' : '#E5E7EB' - } + }, + tickAmount: 5, }, fill: { opacity: 1 @@ -200,23 +201,6 @@ export default function JenisPendaftaranLulusChart({ selectedYear }: Props) { const series = processSeriesData(); - // Calculate the maximum value from all series for y-axis padding - const maxValue = Math.max( - ...series.flatMap(s => s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -265,7 +249,7 @@ export default function JenisPendaftaranLulusChart({ selectedYear }: Props) {
{typeof window !== 'undefined' && series.length > 0 && ( s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -253,7 +238,7 @@ export default function JenisPendaftaranStatusChart({ selectedYear, selectedStat
{typeof window !== 'undefined' && ( s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -283,7 +267,7 @@ export default function LulusTepatWaktuChart({ selectedYear }: Props) {
{typeof window !== 'undefined' && series.length > 0 && ( s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -268,7 +252,7 @@ export default function NamaBeasiswaChart({ selectedYear, selectedJenisBeasiswa
{typeof window !== 'undefined' && series.length > 0 && ( { if (statistikData.length > 0) { - // Calculate the maximum value from all series - const maxValue = Math.max( - ...statistikData.map(item => item.total_mahasiswa), - ...statistikData.map(item => item.pria), - ...statistikData.map(item => item.wanita) - ); - - // Add 50% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); setChartOptions(prev => ({ ...prev, @@ -262,7 +255,6 @@ export default function StatistikMahasiswaChart() { yaxis: [ { ...prev.yaxis[0], - max: yAxisMax } ] })); diff --git a/components/StatusMahasiswaChart.tsx b/components/StatusMahasiswaChart.tsx index 48d2bff..916b74c 100644 --- a/components/StatusMahasiswaChart.tsx +++ b/components/StatusMahasiswaChart.tsx @@ -21,13 +21,15 @@ export default function StatusMahasiswaChart() { const [error, setError] = useState(null); const [data, setData] = useState([]); const [series, setSeries] = useState([]); - const [options, setOptions] = useState({ + + const chartOptions: ApexOptions = { chart: { type: 'bar', stacked: false, toolbar: { show: true, }, + background: theme === 'dark' ? '#0F172B' : '#fff', }, plotOptions: { bar: { @@ -42,7 +44,7 @@ export default function StatusMahasiswaChart() { }, style: { fontSize: '12px', - colors: ['#000'] + colors: [theme === 'dark' ? '#fff' : '#000'] } }, stroke: { @@ -51,19 +53,19 @@ export default function StatusMahasiswaChart() { colors: ['transparent'], }, xaxis: { - categories: [], + categories: [...new Set(data.map(item => item.tahun_angkatan))].sort(), title: { text: 'Tahun Angkatan', style: { fontSize: '14px', fontWeight: 'bold', - color: '#000' + color: theme === 'dark' ? '#fff' : '#000' } }, labels: { style: { fontSize: '12px', - colors: '#000' + colors: theme === 'dark' ? '#fff' : '#000' } } }, @@ -73,15 +75,15 @@ export default function StatusMahasiswaChart() { style: { fontSize: '14px', fontWeight: 'bold', - color: '#000' + color: theme === 'dark' ? '#fff' : '#000' } }, labels: { style: { fontSize: '12px', - colors: '#000' + colors: theme === 'dark' ? '#fff' : '#000' } - } + }, }, fill: { opacity: 1, @@ -96,19 +98,19 @@ export default function StatusMahasiswaChart() { horizontal: 10, }, labels: { - colors: '#000' + colors: theme === 'dark' ? '#fff' : '#000' } }, colors: ['#008FFB', '#00E396', '#FEB019', '#EF4444'], tooltip: { - theme: 'light', + theme: theme === 'dark' ? 'dark' : 'light', y: { formatter: function (val: number) { return val + " mahasiswa"; } } } - }); + }; useEffect(() => { const fetchData = async () => { @@ -143,26 +145,6 @@ export default function StatusMahasiswaChart() { })); setSeries(seriesData); - - // Calculate the maximum value from all series - const maxValue = Math.max( - ...seriesData.flatMap(series => series.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - setOptions(prev => ({ - ...prev, - xaxis: { - ...prev.xaxis, - categories: tahunAngkatan, - }, - yaxis: { - ...prev.yaxis, - max: yAxisMax - } - })); } catch (err) { console.error('Error in fetchData:', err); setError(err instanceof Error ? err.message : 'An error occurred while fetching data'); @@ -174,73 +156,6 @@ export default function StatusMahasiswaChart() { fetchData(); }, []); - // Update theme when it changes - useEffect(() => { - const currentTheme = theme === 'system' ? systemTheme : theme; - const textColor = currentTheme === 'dark' ? '#fff' : '#000'; - const tooltipTheme = currentTheme === 'dark' ? 'dark' : 'light'; - - setOptions(prev => ({ - ...prev, - chart: { - ...prev.chart, - background: currentTheme === 'dark' ? '#0F172B' : '#fff', - }, - dataLabels: { - ...prev.dataLabels, - style: { - ...prev.dataLabels?.style, - colors: [textColor] - } - }, - xaxis: { - ...prev.xaxis, - title: { - ...prev.xaxis?.title, - style: { - ...prev.xaxis?.title?.style, - color: textColor - } - }, - labels: { - ...prev.xaxis?.labels, - style: { - ...prev.xaxis?.labels?.style, - colors: textColor - } - } - }, - yaxis: { - ...(prev.yaxis as ApexYAxis), - title: { - ...(prev.yaxis as ApexYAxis)?.title, - style: { - ...(prev.yaxis as ApexYAxis)?.title?.style, - color: textColor - } - }, - labels: { - ...(prev.yaxis as ApexYAxis)?.labels, - style: { - ...(prev.yaxis as ApexYAxis)?.labels?.style, - colors: textColor - } - } - }, - legend: { - ...prev.legend, - labels: { - ...prev.legend?.labels, - colors: textColor - } - }, - tooltip: { - ...prev.tooltip, - theme: tooltipTheme - } - })); - }, [theme, systemTheme]); - if (loading) { return ( @@ -285,10 +200,10 @@ export default function StatusMahasiswaChart() { -
+
{typeof window !== 'undefined' && ( s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; if (loading) { return ( @@ -255,7 +239,7 @@ export default function StatusMahasiswaFilterChart({ selectedYear, selectedStatu
{typeof window !== 'undefined' && ( s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -266,7 +250,7 @@ export default function TingkatPrestasiChart({ selectedJenisPrestasi }: Props) {
{typeof window !== 'undefined' && series.length > 0 && ( s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -280,7 +264,7 @@ export default function TotalBeasiswaChart({ selectedYear, selectedJenisBeasiswa
{typeof window !== 'undefined' && series.length > 0 && ( s.data) - ); - - // Add 20% padding to the maximum value - const yAxisMax = Math.ceil(maxValue * 1.2); - - // Update chart options with y-axis max - const updatedChartOptions: ApexOptions = { - ...chartOptions, - yaxis: { - ...chartOptions.yaxis, - max: yAxisMax - } - }; - if (loading) { return ( @@ -278,7 +262,7 @@ export default function TotalPrestasiChart({ selectedJenisPrestasi }: Props) {
{typeof window !== 'undefined' && series.length > 0 && (