From a048bd5ca089332d24e852f04a0f4d9d5dee3190 Mon Sep 17 00:00:00 2001 From: bicochan Date: Thu, 5 Jun 2025 17:09:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=A4=EB=AC=B8=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=20=ED=95=AD=EB=AA=A9=20=EC=9E=91=EC=97=85=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/survey/ui/user-survey-result.tsx | 126 +++++++++++++++++- 1 file changed, 122 insertions(+), 4 deletions(-) diff --git a/apps/cs/src/pages/survey/ui/user-survey-result.tsx b/apps/cs/src/pages/survey/ui/user-survey-result.tsx index 96ab5ee55..cbaf9a99f 100644 --- a/apps/cs/src/pages/survey/ui/user-survey-result.tsx +++ b/apps/cs/src/pages/survey/ui/user-survey-result.tsx @@ -1,5 +1,6 @@ "use client"; +import dayjs from "dayjs"; import type { z } from "zod"; import { Fragment, useState } from "react"; import { keepPreviousData, useQuery } from "@tanstack/react-query"; @@ -26,11 +27,21 @@ import { ArcElement, Tooltip, Legend, + CategoryScale, + LinearScale, + BarElement, type PluginChartOptions, } from "chart.js"; -import { Pie } from "react-chartjs-2"; +import { Pie, Bar } from "react-chartjs-2"; -ChartJS.register(ArcElement, Tooltip, Legend); +ChartJS.register( + ArcElement, + CategoryScale, + LinearScale, + BarElement, + Tooltip, + Legend, +); function UserSurveyResult({ srvySn }: { srvySn: string }) { const [params, setParams] = useState({ @@ -124,6 +135,12 @@ function UserSurveyResult({ srvySn }: { srvySn: string }) { {item.qstnTypeCd === "RADIO" && ( )} + {item.qstnTypeCd === "CHECK" && ( + + )} + {item.qstnTypeCd === "INPUT" && ( + + )} ))} @@ -163,7 +180,7 @@ function WithPieChartResult({ }; return ( -
+ <>

{index + 1} @@ -196,7 +213,108 @@ function WithPieChartResult({

- + + ); +} + +function WithBarChartResult({ + data, + index, +}: { + data: QuestionWithArticles; + index: number; +}) { + const labels = data?.articles.map((article) => article.artclCn); + const chartData = { + labels, + datasets: [ + { + label: "응답수", + data: data?.articles.map((article) => article.rspnsCount), + backgroundColor: labels?.map((_, i) => + getCssVariableValue(`--chart-${i + 1}`), + ), + }, + ], + }; + const options = { + plugins: { + legend: { + position: "bottom", + }, + }, + }; + + return ( + <> +

+ + {index + 1} + + {data?.qstnCn} +

+
+
+ } + /> +
+ + + + 항목 + 응답수 + 응답률 + + + + {data?.articles.map((article) => ( + + {article.artclCn} + {article.rspnsCount} + {article.rspnsRate.toFixed(2)}% + + ))} + +
+
+ + ); +} + +function InputResult({ + data, + index, +}: { + data: QuestionWithArticles; + index: number; +}) { + return ( + <> +

+ + {index + 1} + + {data?.qstnCn} +

+
+ {data?.articles[0]?.inputRslts.map((input, index) => ( +
+
+ {input.rspdntNm} + + {dayjs(input.ansDt).format("YYYY-MM-DD")} + +
+

{input.ansCn}

+
+ ))} +
+ ); }