jichoi / lms_front star
정다정 2024-11-29
241129 정다정 학습현황 차트 날짜 오늘 날짜로 변경
@bf2cd9666bdb34a25197e7422a45a107045605c0
client/views/pages/main/chDounutchart.vue
--- client/views/pages/main/chDounutchart.vue
+++ client/views/pages/main/chDounutchart.vue
@@ -1,23 +1,23 @@
 <template>
-    <div ref="Dounutchart" style="position: relative;left: 29px;top: -5px;width: 500px;height: 300px;"></div>
+    <div ref="Dounutchart" style="position: relative; left: 29px; top: -5px; width: 500px; height: 300px"></div>
 </template>
 
 <script>
-import * as am5 from "@amcharts/amcharts5";
-import * as am5percent from "@amcharts/amcharts5/percent";
-import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
-import axios from "axios";
+import * as am5 from '@amcharts/amcharts5';
+import * as am5percent from '@amcharts/amcharts5/percent';
+import am5themes_Animated from '@amcharts/amcharts5/themes/Animated';
+import axios from 'axios';
 
 export default {
-    name: "Dounutchart",
+    name: 'Dounutchart',
 
     data() {
         return {
             chartData: {},
-            currentDate: "2024-08-14",
-            currentStdId: "1",
+            currentDate: '',
+            currentStdId: '2',
             root: null,
-            chart: null
+            chart: null,
         };
     },
 
@@ -26,21 +26,30 @@
     },
 
     methods: {
-
+        // 오늘 날짜로 계산하기
+        formatDate() {
+            const date = new Date();
+            const year = date.getFullYear();
+            const month = ('0' + (date.getMonth() + 1)).slice(-2);
+            const day = ('0' + date.getDate()).slice(-2);
+            this.currentDate = `${year}-${month}-${day}`;
+        },
         // 현재 날짜의 학생 학습률 데이터 가져오기
         getStdProgressData() {
             const vm = this;
-            axios.post('/dashboard/stdProgressData.json', {
-                std_id: vm.currentStdId,
-                current_date: vm.currentDate
-            })
-                .then(response => {
+            vm.formatDate();
+            axios
+                .post('/dashboard/stdProgressData.json', {
+                    std_id: vm.currentStdId,
+                    current_date: vm.currentDate,
+                })
+                .then((response) => {
                     vm.chartData = response.data;
                     vm.createChart();
                 })
-                .catch(error => {
+                .catch((error) => {
                     console.error('오늘의 학생 학습 현황 데이터를 가져오는 중 오류 발생:', error);
-                })
+                });
         },
 
         createChart() {
@@ -53,56 +62,58 @@
             const root = am5.Root.new(this.$refs.Dounutchart);
 
             // Apply themes
-            root.setThemes([
-                am5themes_Animated.new(root)
-            ]);
+            root.setThemes([am5themes_Animated.new(root)]);
 
             // Create chart
-            const chart = root.container.children.push(am5percent.PieChart.new(root, {
-                layout: root.verticalLayout,
-                radius: am5.percent(80),
-                innerRadius: am5.percent(40)  // Adjusted innerRadius for a donut chart
-            }));
+            const chart = root.container.children.push(
+                am5percent.PieChart.new(root, {
+                    layout: root.verticalLayout,
+                    radius: am5.percent(80),
+                    innerRadius: am5.percent(40), // Adjusted innerRadius for a donut chart
+                })
+            );
 
             if (chart.logo) {
                 chart.logo.disabled = true;
-            };
+            }
 
             // Create series
-            const series = chart.series.push(am5percent.PieSeries.new(root, {
-                valueField: "value",
-                categoryField: "category",
-                alignLabels: false
-            }));
+            const series = chart.series.push(
+                am5percent.PieSeries.new(root, {
+                    valueField: 'value',
+                    categoryField: 'category',
+                    alignLabels: false,
+                })
+            );
 
             // 색깔 설정
             series.slices.template.setAll({
                 fill: am5.color(0x008000), // green for completed units
                 strokeWidth: 0,
-                strokeOpacity: 0
+                strokeOpacity: 0,
             });
 
             // 카테고리 별 색깔 설정
-            series.slices.template.adapters.add("fill", (fill, target) => {
-                if (target.dataItem.get("category") === "완료한 단원") {
+            series.slices.template.adapters.add('fill', (fill, target) => {
+                if (target.dataItem.get('category') === '완료한 단원') {
                     return am5.color(0xafe589); // 초록
-                } else if (target.dataItem.get("category") === "남은 단원") {
+                } else if (target.dataItem.get('category') === '남은 단원') {
                     return am5.color(0xf7cece); // 빨강
                 }
                 return fill;
             });
 
             series.labels.template.setAll({
-                textType: "circular",
+                textType: 'circular',
                 centerX: am5.p50,
                 centerY: am5.p50,
-                fontSize: 14
+                fontSize: 14,
             });
 
             // Set data
             series.data.setAll([
-                { value: this.chartData.clearUnitNum, category: "완료한 단원" },
-                { value: this.chartData.totalScheduleUnitNum - this.chartData.clearUnitNum, category: "남은 단원" },
+                { value: this.chartData.clearUnitNum, category: '완료한 단원' },
+                { value: this.chartData.totalScheduleUnitNum - this.chartData.clearUnitNum, category: '남은 단원' },
             ]);
 
             // Create legend
@@ -116,13 +127,11 @@
 
             // Play initial series animation
             series.appear(1000, 100);
-
-        }
-    }
-
+        },
+    },
 };
 </script>
 
 <style scoped>
 /* Add necessary styles here */
-</style>
(No newline at end of file)
+</style>
Add a comment
List