google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(initializeCharts); // 초기화 함수 변경 function initializeCharts() { drawCharts(); setupDarkModeObserver(); // 다크 모드 변경 감지 설정 } function drawCharts() { drawChart(); drawChart2(); } function isDarkMode() { return document.documentElement.classList.contains('dark') || document.body.classList.contains('dark'); } // --- (이하 drawChart와 drawChart2 함수 내용은 동일) --- // --- 그래프 1: 모집/접수 인원 (curve_chart) --- function drawChart() { var data = google.visualization.arrayToDataTable([ ['학년도', '모집인원',{type: 'number', role: 'annotation'}, '접수인원', {type: 'number', role: 'annotation'}], ['2017',288,288,6720,6720],['2018',249,249,6450,6450],['2019',238,238,5557,5557],['2020',251,251,4512,4512],['2021',258,258,4214,4214],['2022',321,321,4076,4076],['2023',403,403,3733,3733],['2024',386,386,3403,3403],['2025',518,518,3417,3417],['2026',697,697,3704,3704], ]); var mode = isDarkMode() ? 'dark' : 'light'; var textColor = mode === 'dark' ? '#E5E7EB' : '#1F2937'; var chartBgColor = mode === 'dark' ? '#1F2937' : '#FFFFFF'; // 💡 색상 배열 동적 수정 var chartColors = ['red', 'blue', 'green', 'black', 'yellow', 'gray']; if (mode === 'dark') { // Dark Mode일 때: 모집인원(red)은 유지, 접수인원(blue)을 대비 좋은 밝은 주황색으로 변경 // [0] red (모집인원), [1] blue -> #FBBF24 (접수인원) chartColors[1] = '#FBBF24'; // Tailwind yellow-500 // Annotation 텍스트 스타일 수정 (글자색이 아닌 외곽선 색상) var annotationStyle = { textStyle: { color: textColor, // 숫자가 잘 보이도록 텍스트 색상을 밝게 설정 auraColor: mode === 'dark' ? '#1F2937' : 'transparent' // 다크 모드 배경색으로 아우라 설정 } }; } else { // Light Mode일 때: 원본 색상 유지 var annotationStyle = { textStyle: { auraColor: '' } }; } var options = { annotations: annotationStyle, // 수정된 Annotation 스타일 적용 curveType: 'bars', pointSize: 5, backgroundColor: { fill: chartBgColor }, titleTextStyle: { color: textColor }, hAxis: { textStyle: { color: textColor }, title: '' }, vAxis: { textStyle: { color: textColor }, gridlines: { color: mode === 'dark' ? '#4B5563' : '#E5E7EB' } }, legend: { position: 'top', textStyle: { color: textColor } }, chartArea:{left:10,right:10,width:"100%",height:"300px"}, colors: chartColors, // 동적으로 변경된 색상 배열 적용 }; var chart = new google.visualization.LineChart(document.getElementById('curve_chart')); chart.draw(data, options); } // --- 그래프 2: 경쟁률 (curve_chart2) --- function drawChart2() { var data = google.visualization.arrayToDataTable([ ['학년도', '경쟁률',{type: 'number', role: 'annotation'}], ['2017',23.33,23.33],['2018',25.90,25.90],['2019',23.35,23.35],['2020',17.98,17.98],['2021',16.33,16.33],['2022',12.70,12.70],['2023',9.26,9.26],['2024',8.82,8.82],['2025',6.60,6.60],['2026',5.31,5.31], ]); var mode = isDarkMode() ? 'dark' : 'light'; var textColor = mode === 'dark' ? '#E5E7EB' : '#1F2937'; var chartBgColor = mode === 'dark' ? '#1F2937' : '#FFFFFF'; var options = { annotations: { textStyle: { auraColor: '' } }, curveType: 'bars', pointSize: 5, backgroundColor: { fill: chartBgColor }, titleTextStyle: { color: textColor }, hAxis: { textStyle: { color: textColor }, title: '' }, vAxis: { textStyle: { color: textColor }, gridlines: { color: mode === 'dark' ? '#4B5563' : '#E5E7EB' } }, legend: { position: 'top', textStyle: { color: textColor } }, chartArea:{left:10,right:10,width:"100%",height:"300px"}, colors: ['green', 'black', 'yellow', 'gray'], }; var chart = new google.visualization.LineChart(document.getElementById('curve_chart2')); chart.draw(data, options); } // 윈도우 크기 변경 감지 window.addEventListener('resize', drawCharts, false); // --- 다크 모드 클래스 변경 감지 로직 --- function setupDarkModeObserver() { const targetNode = document.documentElement; // 태그를 감시 const config = { attributes: true, attributeFilter: ['class'] }; const callback = function(mutationsList, observer) { for(const mutation of mutationsList) { if (mutation.type === 'attributes' && mutation.attributeName === 'class') { // 'dark' 클래스가 추가/제거되었을 가능성이 있으므로 차트를 다시 그립니다. drawCharts(); } } }; const observer = new MutationObserver(callback); observer.observe(targetNode, config); } // ---------------------------------------- /* google.charts.load('current', {'packages': ['bar']}); google.charts.setOnLoadCallback(drawChart3); function drawChart3() { var data = google.visualization.arrayToDataTable([ ['학년도', '모집', { type: 'number', role: 'annotation' }, '접수', { type: 'number', role: 'annotation' }], Warning: mysqli_query(): Couldn't fetch mysqli in /home/imgoya/public_html_ing/js/indexgraph.php on line 158 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/imgoya/public_html_ing/js/indexgraph.php on line 159 ]); var view = new google.visualization.DataView(data); view.setColumns([0, 1, { calc: "stringify", sourceColumn: 2, type: "string", role: "annotation" }, 3, { calc: "stringify", sourceColumn: 4, type: "string", role: "annotation" } ]); var options = { chart: { //title: 'Company Performance', //subtitle: 'Sales, Expenses, and Profit: 2014-2017', curveType: 'bars', pointSize: 5, chartArea: { left: 10, top: 20, width: "100%", height: "300px" }, hAxis: { title: '학년도' }, colors: ['red', 'blue', 'green', 'black', 'yellow', 'gray'], legend: { position: 'top' } } }; var chart = new google.visualization.ColumnChart(document.getElementById("curve_chart3")); chart.draw(view, options); } */