๊ฐ์
Radar ์ฐจํธ๋ฅผ Charts ํ๋ ์์ํฌ๋ฅผ ์ด์ฉํด์ ๋ง๋ค์ด ๋ณด๋ คํ๋ค.

Charts์์๋ ์ฐจํธ์ ๋ฐ์ดํฐ๋ฅผ ์์ฒ๋ผ ๋ฌถ๋๋ค.
๋ณธ๋ก
// 1
let greenDataSet = RadarChartDataSet(
entries: [
RadarChartDataEntry(value: 210),
RadarChartDataEntry(value: 60.0),
RadarChartDataEntry(value: 150.0),
RadarChartDataEntry(value: 150.0),
RadarChartDataEntry(value: 160.0),
RadarChartDataEntry(value: 150.0),
RadarChartDataEntry(value: 110.0),
RadarChartDataEntry(value: 190.0),
RadarChartDataEntry(value: 200.0)
]
)
let redDataSet = RadarChartDataSet(
entries: [
RadarChartDataEntry(value: 120.0),
RadarChartDataEntry(value: 160.0),
RadarChartDataEntry(value: 110.0),
RadarChartDataEntry(value: 110.0),
RadarChartDataEntry(value: 210.0),
RadarChartDataEntry(value: 120.0),
RadarChartDataEntry(value: 210.0),
RadarChartDataEntry(value: 100.0),
RadarChartDataEntry(value: 210.0)
]
)
// 2
let data = RadarChartData(dataSets: [greenDataSet, redDataSet])
// 3
radarChart.data = data
// 1
๋จผ์ ์ฐจํธ์ ํ์ํ ๋ฐ์ดํฐํญ๋ชฉ์ ํฌํจํ๋ ๋๊ฐ์ง ์ธ์คํด์ค๋ฅผ ๋ง๋ ๋ค.
์ฒซ๋ฒ์งธ๋ ๋ น์ ์์ญ์ ๋ํ ํฌ์ธํธ๋ฅผ ํฌํจํ๊ณ ๋๋ฒ์งธ๋ ๋นจ๊ฐ์ ์์ญ์ ๋ํ ํฌ์ธํธ๋ฅผ ํฌํจํ๋ค.
์ด ์์์์ ๊ฐ๊ฐ์ Double๊ฐ์ผ๋ก๋ง ๊ตฌ์ฑ๋์ง๋ง ์์ด์ฝ์ ์ถ๊ฐํ๊ณ ํญ๋ชฉ์ ๋ํ ์์ ๋ฐ์ดํฐ๋ฅผ ์ ์ํ ์๋ ์๋ค.
// 2
๋ dataSet์ ์์ฑ์๋ก ์ ๋ฌํ์ฌ ๋ํํ๋ค.
// 3
๋ง์ง๋ง์ผ๋ก ์์ฑ๋ ๋ฐ์ดํฐ ๊ฐ์ฒด์ ์์ฑ์ ์ค์ ํ๋ค.

DataSet ๋ ์ด์์ ์ฌ์ฉ์์ง์
// 1
redDataSet.lineWidth = 2
// 2
let redColor = UIColor(red: 247/255, green: 67/255, blue: 115/255, alpha: 1)
let redFillColor = UIColor(red: 247/255, green: 67/255, blue: 115/255, alpha: 0.6)
redDataSet.colors = [redColor]
redDataSet.fillColor = redFillColor
redDataSet.drawFilledEnabled = true
// 3
redDataSet.valueFormatter = DataSetValueFormatter()
// 1
๋จผ์ ์์ฑ์ lineWidth ๊ธฐ๋ณธ๊ฐ์์ 2๋ก ๋๋ฆฐ๋ค.
์ ์ ์ฐ๊ฒฐํ๋ ์ ์ Width๋ฅผ ๋๋ ธ๋ค.
// 2
๋นจ๊ฐ์์ผ๋ก ์ปค์คํ ํ๊ธฐ ์ํด ์์ฑํ ์ฝ๋๋ค
drawFilledEnabled ์์ฑ์ true๋ก ์ค์ ํ๋ฉด ๋ฐฉ์ฌํ ์ฐจํธ ๋ด๋ถ๊ฐ fillColor๋ก ์น ํด์ง๋ค.
// 3
valueFormatter๋ ์๋์์ ์ค๋ช ์์

์ฐจํธ ๋ทฐ ์์ฑ ๊ตฌ์ฑ
// 1
@IBOutlet weak var radarChart: RadarChartView!
// 2
radarChart.webLineWidth = 1.5
radarChart.innerWebLineWidth = 1.5
radarChart.webColor = .lightGray
radarChart.innerWebColor = .lightGray
// 3
let xAxis = radarChart.xAxis
xAxis.labelFont = .systemFont(ofSize: 9, weight: .bold)
xAxis.labelTextColor = .black
xAxis.xOffset = 10
xAxis.yOffset = 10
xAxis.valueFormatter = XAxisFormatter()
// 4
let yAxis = radarChart.yAxis
yAxis.labelFont = .systemFont(ofSize: 9, weight: .light)
yAxis.labelCount = 6
yAxis.drawTopYLabelEntryEnabled = false
yAxis.axisMinimum = 0
yAxis.valueFormatter = YAxisFormatter()
// 5
radarChart.rotationEnabled = false
radarChart.legend.enabled = false
Formatter
// 1
class DataSetValueFormatter: IValueFormatter {
func stringForValue(_ value: Double,
entry: ChartDataEntry,
dataSetIndex: Int,
viewPortHandler: ViewPortHandler?) -> String {
""
}
}
// 2
class XAxisFormatter: IAxisValueFormatter {
let titles = "ABCDEFGHI".map { "Party \($0)" }
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
titles[Int(value) % titles.count]
}
}
// 3
class YAxisFormatter: IAxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
"\(Int(value)) $"
}
}

SwiftUI์์์ ์ฌ์ฉ
// 1
struct RadarView: UIViewRepresentable {
// 2
typealias UIViewType = RadarChartView
// 3
func makeUIView(context: UIViewRepresentableContext<RadarView>) -> RadarChartView {
let radarChart = RadarChartView()
// Setup radar Chart
return radarChart
}
// 4
@State var data: RadarChartData
func updateUIView(_ uiView: RadarChartView, context: UIViewRepresentableContext<RadarView>) {
uiView.data = data
}
}
Ref
https://betterprogramming.pub/creating-a-radar-chart-in-swift-5791afcf92f0
Create a Radar Chart in Swift
Plotting data with the framework, Charts
betterprogramming.pub
https://github.com/danielgindi/Charts
GitHub - danielgindi/Charts: Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart. - GitHub - danielgindi/Charts: Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroi...
github.com
'๐ iOS > SwiftUI' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SwiftUI] Custom Picker (0) | 2023.12.22 |
---|---|
Introspect (0) | 2023.12.06 |
[์ฑ์คํ ์ด ๋ฆฌ์ ] Guideline 4.3 - Design - Spam (0) | 2023.03.14 |
[SwiftUI] ์ ๋๋ชน ๋ฐฐ๋๊ด๊ณ ๋ฌ๊ธฐ (0) | 2023.03.02 |
git@my_private_repo.git: An unknown error occurred. reference 'refs/remotes/origin/main' not found (-1) ์ค๋ฅ ํด๊ฒฐ (0) | 2023.03.02 |
๊ฐ์
Radar ์ฐจํธ๋ฅผ Charts ํ๋ ์์ํฌ๋ฅผ ์ด์ฉํด์ ๋ง๋ค์ด ๋ณด๋ คํ๋ค.

Charts์์๋ ์ฐจํธ์ ๋ฐ์ดํฐ๋ฅผ ์์ฒ๋ผ ๋ฌถ๋๋ค.
๋ณธ๋ก
// 1
let greenDataSet = RadarChartDataSet(
entries: [
RadarChartDataEntry(value: 210),
RadarChartDataEntry(value: 60.0),
RadarChartDataEntry(value: 150.0),
RadarChartDataEntry(value: 150.0),
RadarChartDataEntry(value: 160.0),
RadarChartDataEntry(value: 150.0),
RadarChartDataEntry(value: 110.0),
RadarChartDataEntry(value: 190.0),
RadarChartDataEntry(value: 200.0)
]
)
let redDataSet = RadarChartDataSet(
entries: [
RadarChartDataEntry(value: 120.0),
RadarChartDataEntry(value: 160.0),
RadarChartDataEntry(value: 110.0),
RadarChartDataEntry(value: 110.0),
RadarChartDataEntry(value: 210.0),
RadarChartDataEntry(value: 120.0),
RadarChartDataEntry(value: 210.0),
RadarChartDataEntry(value: 100.0),
RadarChartDataEntry(value: 210.0)
]
)
// 2
let data = RadarChartData(dataSets: [greenDataSet, redDataSet])
// 3
radarChart.data = data
// 1
๋จผ์ ์ฐจํธ์ ํ์ํ ๋ฐ์ดํฐํญ๋ชฉ์ ํฌํจํ๋ ๋๊ฐ์ง ์ธ์คํด์ค๋ฅผ ๋ง๋ ๋ค.
์ฒซ๋ฒ์งธ๋ ๋ น์ ์์ญ์ ๋ํ ํฌ์ธํธ๋ฅผ ํฌํจํ๊ณ ๋๋ฒ์งธ๋ ๋นจ๊ฐ์ ์์ญ์ ๋ํ ํฌ์ธํธ๋ฅผ ํฌํจํ๋ค.
์ด ์์์์ ๊ฐ๊ฐ์ Double๊ฐ์ผ๋ก๋ง ๊ตฌ์ฑ๋์ง๋ง ์์ด์ฝ์ ์ถ๊ฐํ๊ณ ํญ๋ชฉ์ ๋ํ ์์ ๋ฐ์ดํฐ๋ฅผ ์ ์ํ ์๋ ์๋ค.
// 2
๋ dataSet์ ์์ฑ์๋ก ์ ๋ฌํ์ฌ ๋ํํ๋ค.
// 3
๋ง์ง๋ง์ผ๋ก ์์ฑ๋ ๋ฐ์ดํฐ ๊ฐ์ฒด์ ์์ฑ์ ์ค์ ํ๋ค.

DataSet ๋ ์ด์์ ์ฌ์ฉ์์ง์
// 1
redDataSet.lineWidth = 2
// 2
let redColor = UIColor(red: 247/255, green: 67/255, blue: 115/255, alpha: 1)
let redFillColor = UIColor(red: 247/255, green: 67/255, blue: 115/255, alpha: 0.6)
redDataSet.colors = [redColor]
redDataSet.fillColor = redFillColor
redDataSet.drawFilledEnabled = true
// 3
redDataSet.valueFormatter = DataSetValueFormatter()
// 1
๋จผ์ ์์ฑ์ lineWidth ๊ธฐ๋ณธ๊ฐ์์ 2๋ก ๋๋ฆฐ๋ค.
์ ์ ์ฐ๊ฒฐํ๋ ์ ์ Width๋ฅผ ๋๋ ธ๋ค.
// 2
๋นจ๊ฐ์์ผ๋ก ์ปค์คํ ํ๊ธฐ ์ํด ์์ฑํ ์ฝ๋๋ค
drawFilledEnabled ์์ฑ์ true๋ก ์ค์ ํ๋ฉด ๋ฐฉ์ฌํ ์ฐจํธ ๋ด๋ถ๊ฐ fillColor๋ก ์น ํด์ง๋ค.
// 3
valueFormatter๋ ์๋์์ ์ค๋ช ์์

์ฐจํธ ๋ทฐ ์์ฑ ๊ตฌ์ฑ
// 1
@IBOutlet weak var radarChart: RadarChartView!
// 2
radarChart.webLineWidth = 1.5
radarChart.innerWebLineWidth = 1.5
radarChart.webColor = .lightGray
radarChart.innerWebColor = .lightGray
// 3
let xAxis = radarChart.xAxis
xAxis.labelFont = .systemFont(ofSize: 9, weight: .bold)
xAxis.labelTextColor = .black
xAxis.xOffset = 10
xAxis.yOffset = 10
xAxis.valueFormatter = XAxisFormatter()
// 4
let yAxis = radarChart.yAxis
yAxis.labelFont = .systemFont(ofSize: 9, weight: .light)
yAxis.labelCount = 6
yAxis.drawTopYLabelEntryEnabled = false
yAxis.axisMinimum = 0
yAxis.valueFormatter = YAxisFormatter()
// 5
radarChart.rotationEnabled = false
radarChart.legend.enabled = false
Formatter
// 1
class DataSetValueFormatter: IValueFormatter {
func stringForValue(_ value: Double,
entry: ChartDataEntry,
dataSetIndex: Int,
viewPortHandler: ViewPortHandler?) -> String {
""
}
}
// 2
class XAxisFormatter: IAxisValueFormatter {
let titles = "ABCDEFGHI".map { "Party \($0)" }
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
titles[Int(value) % titles.count]
}
}
// 3
class YAxisFormatter: IAxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
"\(Int(value)) $"
}
}

SwiftUI์์์ ์ฌ์ฉ
// 1
struct RadarView: UIViewRepresentable {
// 2
typealias UIViewType = RadarChartView
// 3
func makeUIView(context: UIViewRepresentableContext<RadarView>) -> RadarChartView {
let radarChart = RadarChartView()
// Setup radar Chart
return radarChart
}
// 4
@State var data: RadarChartData
func updateUIView(_ uiView: RadarChartView, context: UIViewRepresentableContext<RadarView>) {
uiView.data = data
}
}
Ref
https://betterprogramming.pub/creating-a-radar-chart-in-swift-5791afcf92f0
Create a Radar Chart in Swift
Plotting data with the framework, Charts
betterprogramming.pub
https://github.com/danielgindi/Charts
GitHub - danielgindi/Charts: Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart. - GitHub - danielgindi/Charts: Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroi...
github.com
'๐ iOS > SwiftUI' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SwiftUI] Custom Picker (0) | 2023.12.22 |
---|---|
Introspect (0) | 2023.12.06 |
[์ฑ์คํ ์ด ๋ฆฌ์ ] Guideline 4.3 - Design - Spam (0) | 2023.03.14 |
[SwiftUI] ์ ๋๋ชน ๋ฐฐ๋๊ด๊ณ ๋ฌ๊ธฐ (0) | 2023.03.02 |
git@my_private_repo.git: An unknown error occurred. reference 'refs/remotes/origin/main' not found (-1) ์ค๋ฅ ํด๊ฒฐ (0) | 2023.03.02 |