Design app experiences with charts

RSS for tag

Discuss the WWDC22 Session Design app experiences with charts

Posts under wwdc2022-110342 tag

4 Posts
Sort by:
Post marked as solved
1 Replies
150 Views
I want to draw a chart where I have two line marks (one for each child each) and behind it area marks for percentiles. If I don't add any foregroundStyle then the line marks get connected. struct GrowthChart: View { @ChartContentBuilder func oneSlice(row: PercentileRow, slice: Slice) -> some ChartContent { AreaMark( x: .value("Day", row.month), yStart: .value("Max", row.dictionary[slice.startKey]!), yEnd: .value("Min", row.dictionary[slice.endKey]!) ) .foregroundStyle(by: .value("Percentile", slice.number)) } let percentileColors: [Color] = [ .blue.opacity(0.1),   .blue.opacity(0.2),   .blue.opacity(0.3),   .blue.opacity(0.4),   .blue.opacity(0.5),   .blue.opacity(0.4),   .blue.opacity(0.3),   .blue.opacity(0.2),   .blue.opacity(0.1)   ] var body: some View { VStack { Chart { ForEach(percentiles.rows) { row in ForEach(slices) { slice in oneSlice(row: row, slice: slice) } } ForEach(children) { child in ForEach(child.data) { dataPoint in LineMark( x: .value("Month", dataPoint.month), y: .value("Height", dataPoint.height) ) .foregroundStyle(by: .value("Name", child.name)) } } } .chartForegroundStyleScale( range: Gradient (colors: percentileColors) ) .aspectRatio(contentMode: .fit) .padding() Spacer() }.padding() } } I don't understand how to group the individual marks. Apparently you have to add a foregroundStyle to each with a .by specifying a category. I found this chartForegroundStyleScale in an example on the internet, but I can only get it to show this gradient. But how do I specify different colors for the LineMarks?
Posted Last updated
.
Post not yet marked as solved
1 Replies
166 Views
I have a dataset I want to have split between past/historic data and future/predicted data. The values for the predicted data take the last value from pastData and apply a decay function to show how much of something is left. I have the data split into two arrays (sampleData_History and sampleData_Future); I have also attempted this with the data combined (sampleData) and tried a conditional in the .foregroundStyle property. Chart { ForEach(sampleData_History) { item in RuleMark(x: .value("Now", Date.now, unit: .hour)).foregroundStyle(.orange) LineMark( x: .value("time", item.date, unit: .hour), y: .value("mg", item.amount) ) .foregroundStyle(Color.blue) AreaMark( x: .value("time", item.date, unit: .hour), y: .value("mg", item.amount) ).foregroundStyle(Color.teal.opacity(0.2)) } ForEach(sampleData_Future) { item in LineMark( x: .value("time", item.date, unit: .hour), y: .value("mg", item.amount) ) .foregroundStyle(Color.red) AreaMark( x: .value("time", item.date, unit: .hour), y: .value("mg", item.amount) ).foregroundStyle(Color.red.opacity(0.2)) } } The above code yields the screenshot below. In the ideal case, I'd like to have everything AFTER the RuleMark line be a different color. Am I missing something? Where might I look to figure this out? EDIT: I have also tried separating them into series to no avail
Posted
by zt01zg.
Last updated
.
Post not yet marked as solved
1 Replies
259 Views
I'm playing around with the new Swift Charts, so far everything is rather straight forward, however I'm looking for a way to change the time frame/scope of the chart. For example, recreating the Heart Rate chart in the Health App or in other words, only showing a subsection of the data, and being able to move the x-axis for left/right for more data. I know it's early, but anyone have any ideas how that might be done?
Posted Last updated
.