-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPieChartBeta.swift
84 lines (71 loc) · 2.36 KB
/
PieChartBeta.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
////
//// PieChartBeta.swift
//// Pie Charts
////
//// Created by I3LT-040 on 6/9/23.
////
//
//import SwiftUI
//import Charts
//
//
//
//
//#Preview {
// PieChartBeta()
//}
import SwiftUI
import Charts
@available(macOS 14.0, *)
struct PlottableValue: Identifiable {
var id = UUID()
var name: String
var value: Double
var color: Color
}
struct PieChartExampleView: View {
let data = [
(name: "Pop", count: 6, color: Color(red: 0.8, green: 0.5, blue: 0, opacity: 0.5)),
(name: "Rock", count: 2, color: Color(red: 0.7, green: 0.4, blue: 0, opacity: 1)),
(name: "Indie", count: 3, color: Color(red: 0.6, green: 0.3, blue: 0, opacity: 1)),
(name: "Jazz", count: 4, color: Color(red: 0.5, green: 0.2, blue: 0, opacity: 1)),
(name: "Hip-Hop", count: 5, color: Color(red: 0.4, green: 0.1, blue: 0, opacity: 1)),
(name: "R&B", count: 7, color: Color(red: 0.3, green: 0, blue: 0, opacity: 1)),
]
var body: some View {
VStack{
Text("Steve Jobs")
.font(
.title2
)
.bold()// FOR CHANGING NAME
ZStack{
Chart(data, id: \.name) { name, count, color in
SectorMark(angle: .value("Value", count),
innerRadius: .ratio(0.8),
angularInset: 1.5)
.cornerRadius(5)
.foregroundStyle(color)
}
// .foregroundStyle( // Gradient shading
// LinearGradient(
// colors: [ .orange,.yellow],
// startPoint: .leading,
// endPoint: .trailing
// )
// )
.frame(height: 300)
Image("CirclePicture") // Replace with your image asset name
.resizable()
.frame(width: 234, height: 234)
.clipShape(Circle())
.overlay(Circle().stroke(Color.white, lineWidth: 0))
}
Spacer()
}
}
}
@available(macOS 14.0, *)
#Preview {
PieChartExampleView()
}