jichoi / lms_front star
woals 2024-08-19
240819 권민수 학부모 대시보드 학습현황 시각화 적용
@667252fc5a11b2f6a0bc2d993538d660730412aa
client/views/pages/main/Chapter/Chapter3_3.vue
--- client/views/pages/main/Chapter/Chapter3_3.vue
+++ client/views/pages/main/Chapter/Chapter3_3.vue
@@ -84,7 +84,6 @@
 
     // 단원 정보를 불러오는 API 호출
     fetchUnitDetail(unitId) {
-        console.log("테스트", this.dataList);
         axios.post('/unit/unitDetail.json', {
             unitId: unitId
         })
client/views/pages/parents/Dounutchart.vue
--- client/views/pages/parents/Dounutchart.vue
+++ client/views/pages/parents/Dounutchart.vue
@@ -6,13 +6,41 @@
 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",
-  mounted() {
-    this.createChart();
+
+  data() {
+    return {
+      chartData: {},
+      currentDate: "2024-08-14",
+      currentStdId: "1"
+    };
   },
+
+  mounted() {
+    this.getStdProgressData();
+  },
+
   methods: {
+
+    // 현재 날짜의 학생 학습률 데이터 가져오기
+    getStdProgressData() {
+      const vm = this;
+      axios.post('/dashboard/stdProgressData.json', {
+          std_id: vm.currentStdId,
+          current_date: vm.currentDate
+      })
+      .then(response => {
+        vm.chartData = response.data;
+        vm.createChart();
+      })
+      .catch(error => {
+          console.error('오늘의 학생 학습 현황 데이터를 가져오는 중 오류 발생:', error);
+      })
+    },
+
     createChart() {
       // Initialize root
       const root = am5.Root.new(this.$refs.Dounutchart);
@@ -47,6 +75,23 @@
       //   fontWeight: "bold"
       // }));
 
+      // 색깔 설정
+      series.slices.template.setAll({
+        fill: am5.color(0x008000), // green for completed units
+        strokeWidth: 0,
+        strokeOpacity: 0
+      });
+
+      // 카테고리 별 색깔 설정
+      series.slices.template.adapters.add("fill", (fill, target) => {
+        if (target.dataItem.get("category") === "완료한 단원") {
+          return am5.color(0xafe589); // 초록
+        } else if (target.dataItem.get("category") === "남은 단원") {
+          return am5.color(0xf7cece); // 빨강
+        }
+        return fill;
+      });
+
       series.labels.template.setAll({
         textType: "circular",
         centerX: am5.p50,
@@ -55,8 +100,8 @@
 
       // Set data
       series.data.setAll([
-        { value: 10, category: "One" },
-        { value: 9, category: "Two" },
+        { value: this.chartData.clearUnitNum, category: "완료한 단원" },
+        { value: this.chartData.totalScheduleUnitNum - this.chartData.clearUnitNum, category: "남은 단원" },
       ]);
 
       // Create legend
@@ -73,6 +118,7 @@
       series.appear(1000, 100);
     }
   }
+  
 };
 </script>
 
client/views/pages/parents/Main_p.vue
--- client/views/pages/parents/Main_p.vue
+++ client/views/pages/parents/Main_p.vue
@@ -100,10 +100,15 @@
                             <div><Dounutchart/></div>
                             <div class="textbox">
                                 <p class="title2">오늘의 학습현황</p>
-                                <p class="name">40%</p>
+                                <!-- 안전하게 진도율을 소수점 한자리 수까지 표시 -->
+                                <p class="name"> 
+                                    {{ donutChartData.clearUnitNum && donutChartData.totalScheduleUnitNum 
+                                        ? (donutChartData.clearUnitNum / donutChartData.totalScheduleUnitNum * 100).toFixed(1) 
+                                        : 0 }} %
+                                </p>
                             </div>
                             <p class="title2">학습시간</p>
-                            <p class="name">학습시간 0시간</p>
+                            <p class="name">학습시간 n시간</p>
                         </div>
                         <div class="wrap">
                             <p class="name">이해/표현 점수</p>
@@ -176,28 +181,53 @@
 import Bubblechart from './Bubblechart.vue';
 import Dounutchart from './Dounutchart.vue';
 import ColumnLineChart from './ColumnLineChart.vue';
+import axios from "axios";
 
 export default {
+
     data() {
         return {
-            progress: 20
+            progress: 20,
+            donutChartData: {},
+            currentDate: "2024-08-14",
+            currentStdId: "1"
         }
     },
+
     methods: {
+
         increaseProgress() {
             if (this.progress < 100) {
                 this.progress += 10;
             }
         },
        
+        // 현재 날짜의 학생 학습률 데이터 가져오기
+        getStdProgressData() {
+            const vm = this;
+            axios.post('/dashboard/stdProgressData.json', {
+                std_id: vm.currentStdId,
+                current_date: vm.currentDate
+            })
+            .then(response => {
+                vm.donutChartData = response.data;
+                console.log(vm.donutChartData);
+            })
+            .catch(error => {
+                console.error('오늘의 학생 학습 현황 데이터를 가져오는 중 오류 발생:', error);
+            })
+        },
 
     },
+
     watch: {
 
     },
+
     computed: {
 
     },
+
     components: {
         Header: Header,
         Menu: Menu,
@@ -211,10 +241,14 @@
         ColumnLineChart: ColumnLineChart,
 
     },
+
     mounted() {
+        this.getStdProgressData();
     }
+
 }
 </script>
+
 <style scoped>
 .main-wrap {
     margin-top: 20px;
Add a comment
List