Design app experiences with charts

RSS for tag

Discuss the WWDC22 Session Design app experiences with charts

Posts under wwdc2022-110342 tag

5 Posts

Post

Replies

Boosts

Views

Activity

SwiftUI Charts AxisValueLabel disappears when using centered: true
Hi there, When using the AxisValueLabel in Swift Charts, the moment you add centered: true, the month or day on the right disappears. This has been a bug for over five months since I looked through other developer forums and they had the same issue. AxisValueLabel(format: .dateTime.weekday(), centered: true) leads to the following view: Now if we remove the centered: true, saturday will appear. It is probably a spacing issue, but since these are modifiers provided by Apple, it should do it correctly, right? If I am missing something and this is by desing, please enlighten me. Best Til
1
0
1.5k
Aug ’23
How to Handle Split Data in `Charts`?
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
5
0
2.2k
Jun ’23
SwiftCharts: how to manage colors and groupings
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?
1
0
2.3k
Jun ’22
Changing the Timeframe of Charts
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?
1
0
1.8k
Jun ’22
SwiftUI Charts AxisValueLabel disappears when using centered: true
Hi there, When using the AxisValueLabel in Swift Charts, the moment you add centered: true, the month or day on the right disappears. This has been a bug for over five months since I looked through other developer forums and they had the same issue. AxisValueLabel(format: .dateTime.weekday(), centered: true) leads to the following view: Now if we remove the centered: true, saturday will appear. It is probably a spacing issue, but since these are modifiers provided by Apple, it should do it correctly, right? If I am missing something and this is by desing, please enlighten me. Best Til
Replies
1
Boosts
0
Views
1.5k
Activity
Aug ’23
How to Handle Split Data in `Charts`?
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
Replies
5
Boosts
0
Views
2.2k
Activity
Jun ’23
SwiftCharts: how to manage colors and groupings
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?
Replies
1
Boosts
0
Views
2.3k
Activity
Jun ’22
Changing the Timeframe of Charts
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?
Replies
1
Boosts
0
Views
1.8k
Activity
Jun ’22
Design app experience with Charts -- Accessibility
What are the accessibility considerations when designing a chart? Can we use just color to denote different topics? Or do we need to include symbols like on Fitness to help those who have color blindness understand the charts?
Replies
0
Boosts
1
Views
949
Activity
Jun ’22