diff --git a/2022/Playgrounds/ChartView.swift b/2022/Playgrounds/ChartView.swift new file mode 100644 index 00000000..d897d3db --- /dev/null +++ b/2022/Playgrounds/ChartView.swift @@ -0,0 +1,134 @@ +// +// ChartView.swift +// LetSwift +// +// Created by 이가은 on 2022/11/01. +// + +import SwiftUI +import Charts + +struct ChartView: View { + @StateObject var viewModel = ChartViewModel() + + var body: some View { + TabView { + totalChart() + individualChart() + } + .tabViewStyle(PageTabViewStyle()) + .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always)) + } +} + +extension ChartView { + @ViewBuilder + func totalChart() -> some View { + VStack(alignment: .leading) { + if let chartDataList = viewModel.totalChartDataList { + if #available(iOS 16.0, *) { + VStack(alignment: .leading) { + Text("Let’Swift 22 참여자 개발 성향") + .padding(.bottom, 30) + .font(.title) + Chart { + ForEach(chartDataList) { chartData in + if let question = TempChartData.questionList.first(where: { $0.surveyId == chartData.surveyId })?.question, + let answer = TempChartData.getCardCase(answerId: chartData.answerId) + { + BarMark( + x: .value("Category", answer.rawValue), + y: .value("Profit", chartData.count) + ) + .foregroundStyle(by: .value("Product Category", question)) + } + } + } + .frame(height: 500) + } + } else { + Text("iOS 16.0 부터 결과를 확인할 수 있습니다 :)") + } + } else { +#warning("이미지 넣기") + Text("로딩중...") + } + Spacer() + } + .padding(.top, 50) + .padding(.horizontal, 30) + } + @ViewBuilder + func individualChart() -> some View { + ScrollView(showsIndicators: false) { + VStack(alignment: .leading) { + Text("답변 전체 결과 보기") + .padding(.bottom, 30) + .font(.title) + if let chartData = viewModel.chartData { + if #available(iOS 16.0, *) { + ForEach(0..