Hi, I have two charts on the page and you can switch between them with the picker. Can you please tell me how can I make them show with animation? I do not know how to start the animation when I change a chart in the picker. Thank you!
struct ChartsView: View {
var stackedBarData: [ToyShape] = [
.init(type: "Cube", count: 0),
.init(type: "Sphere", count: 0),
.init(type: "Pyramid", count: 1),
]
var charts = ["Bar chart", "Area chart"]
@State private var selectedChart = "Bar chart"
var body: some View {
VStack {
if selectedChart == "Bar chart" {
Chart {
ForEach(stackedBarData) { shape in
BarMark(
x: .value("Shape Type", shape.type),
y: .value("Total Count", shape.count)
)
}
}
.padding(.vertical, 20)
} else if selectedChart == "Area chart" {
Chart {
ForEach(stackedBarData) { shape in
AreaMark(
x: .value("Shape Type", shape.type),
y: .value("Total Count", shape.count)
)
}
}
.padding(.vertical, 20)
}
Picker("Select a chart", selection: $selectedChart) {
ForEach(charts, id: \.self) {
Text($0)
}
}
.pickerStyle(.segmented)
}
.padding(16)
}
}