Swift Charts

RSS for tag

Visualize data with highly customizable charts across all Apple platforms using the compositional syntax of SwifUI.

Posts under Swift Charts tag

192 Posts

Post

Replies

Boosts

Views

Activity

Charts: customising chartYAxis values
anyone figured out how to customise the Y axis values? id like to be able to process the. axis values and. then display them in the. format id like. eg. "1000" I'd like to display as "1k" the furthest Ive been able to get is to get the axis to display a static text as the number ie "Y" in the code below. but I haven't been able to access the value. in the code below 'value' seems to be an AxisValue which stores the value but I can't seem to access it in a format I can process. .chartYAxis {                 AxisMarks() { value in                     AxisGridLine()                     AxisTick()                     AxisValueLabel {                     Text("Y")                     }                 }             } id like to be able to do something like this: .chartYAxis {                 AxisMarks() { value in                     AxisGridLine()                     AxisTick()                     AxisValueLabel {                         if value > 1000000000000.0 {                             Text("\(value / 1000000000000.0)t")                         } else if value > 1000000000.0 {                             Text("\(value / 1000000000.0)b")                         } else if value > 1000000.0 {                             Text("\(value / 1000000.0)m")                         } else if value > 1000.0 {                             Text("\(value / 1000.0)k")                         }                     }                 }             }
5
2
6k
Jun ’22
Orientation (vertical, angle) in Swift Charts is not working
Hi! I want to use the new SwiftUI Charts (iOS 16) in my app and it seems that the orientation does not work. I want to make the AxisLabels vertical oder verticalReversed or give it a certain angle but all three methods don't seem to work. AxisMarks() { _ in AxisValueLabel(orientation: .angle(Angle.degrees(45.0))) } } Am i doing something wrong or is it a bug in the beta framework? Kind regards, Tom
0
0
942
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
Axis with fixed domain range without rounding
I am using .chartYScale(domain: 0...12) to define a Y axis from 0 to 12, but the chart will always display 0 to 15, i.e. it will round the given values up to the next "nice one". However, I don't want this in my use case. How do I tell the chart to use exactly the provided range and don't adjust it automatically?
1
1
891
Jun ’22
LineMark Does Not Respect .foregroundStyle Color choice
Working through the new Swift Chart framework and I am noticing LineMark does not seem to want to respect .foregroundStyle(.pink) (or any respective color) for more than one line. Apple's own Chart page lists an example that, when copied into Xcode 14 (beta 1) it does not render in preview as it does in their screenshot Data used: struct ProfitOverTime { var week: Int var profit: Double } let departmentAProfile: [ProfitOverTime] = [ .init(week: 1, profit: 21.5), .init(week: 2, profit: 19.2), .init(week: 3, profit: 18.4), .init(week: 4, profit: 21.0), .init(week: 5, profit: 19.7), .init(week: 6, profit: 14.7), .init(week: 7, profit: 22.1), .init(week: 8, profit: 18.0) ] let departmentBProfile: [ProfitOverTime] = [ .init(week: 1, profit: 5.7), .init(week: 2, profit: 12.0), .init(week: 3, profit: 11.9), .init(week: 4, profit: 18.0), .init(week: 5, profit: 15.9), .init(week: 6, profit: 16.7), .init(week: 7, profit: 12.1), .init(week: 8, profit: 19.0) ] Content View: struct ContentView: View {     var body: some View { Chart { ForEach(departmentAProfile, id: \.week) { LineMark( x: .value("Week", $0.week), y: .value("Profit A", $0.profit) ).foregroundStyle(.green) } ForEach(departmentBProfile, id: \.week) { LineMark( x: .value("Week", $0.week), y: .value("Profit B", $0.profit) ) .foregroundStyle(.green) } RuleMark( y: .value("Threshold", 20.0) ) .foregroundStyle(.teal) }     } } Produces
2
0
2.2k
Jun ’22
Auto zooming on data variation chart type & Axis breaks symbols
A lot of time when you plot a chart (say a bar chart here) for business you wants to emphasize the small variation between data, say daily you have roughly 5 millions messages sent but you need to visualize the 3k variations common each days. To utilize the landscape it's best for one to visualize not from zero but zooming in between 4.9m ~ 5.2m range instead of showing a slightly wiggling line. While we could likely (I haven't get to it) to customize our chart to do that it'd be a good and handy option for the standard charts and Swift Chart would auto-adjust the range. On top of it, being able to add standard axis break symbols would be a great help to keep it visualized and keep the chart honest.
0
0
893
Jun ’22
Charts: customising chartYAxis values
anyone figured out how to customise the Y axis values? id like to be able to process the. axis values and. then display them in the. format id like. eg. "1000" I'd like to display as "1k" the furthest Ive been able to get is to get the axis to display a static text as the number ie "Y" in the code below. but I haven't been able to access the value. in the code below 'value' seems to be an AxisValue which stores the value but I can't seem to access it in a format I can process. .chartYAxis {                 AxisMarks() { value in                     AxisGridLine()                     AxisTick()                     AxisValueLabel {                     Text("Y")                     }                 }             } id like to be able to do something like this: .chartYAxis {                 AxisMarks() { value in                     AxisGridLine()                     AxisTick()                     AxisValueLabel {                         if value > 1000000000000.0 {                             Text("\(value / 1000000000000.0)t")                         } else if value > 1000000000.0 {                             Text("\(value / 1000000000.0)b")                         } else if value > 1000000.0 {                             Text("\(value / 1000000.0)m")                         } else if value > 1000.0 {                             Text("\(value / 1000.0)k")                         }                     }                 }             }
Replies
5
Boosts
2
Views
6k
Activity
Jun ’22
SwiftCharts: How do I make PointMarks only a dot?
Is there a way to have a point mark only come out as a very small circle? I want PointMarks that are basically just 1 point large black dots.
Replies
1
Boosts
0
Views
1.6k
Activity
Jun ’22
Orientation (vertical, angle) in Swift Charts is not working
Hi! I want to use the new SwiftUI Charts (iOS 16) in my app and it seems that the orientation does not work. I want to make the AxisLabels vertical oder verticalReversed or give it a certain angle but all three methods don't seem to work. AxisMarks() { _ in AxisValueLabel(orientation: .angle(Angle.degrees(45.0))) } } Am i doing something wrong or is it a bug in the beta framework? Kind regards, Tom
Replies
0
Boosts
0
Views
942
Activity
Jun ’22
How do you manually set a range on a chart
How can you set a manual range on a chart? There is .chartXScale(range:) but the only options seem to be to add padding to the values in the chart. I need to have a specific start and end date.
Replies
1
Boosts
0
Views
1k
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
Axis with fixed domain range without rounding
I am using .chartYScale(domain: 0...12) to define a Y axis from 0 to 12, but the chart will always display 0 to 15, i.e. it will round the given values up to the next "nice one". However, I don't want this in my use case. How do I tell the chart to use exactly the provided range and don't adjust it automatically?
Replies
1
Boosts
1
Views
891
Activity
Jun ’22
SwiftUI Updates
Hi SwiftUI updates such as Charts are available to use now or till the new OS launches in coming fall ? Kindest Regards
Replies
2
Boosts
0
Views
912
Activity
Jun ’22
Custom Marks
How does one create a custom mark for Swift Charts? I'm trying to add a live indicator to a stock app line mark. Is a custom mark the best way to do this?
Replies
0
Boosts
0
Views
1k
Activity
Jun ’22
piecharts
Are PieCharts supported?
Replies
0
Boosts
0
Views
406
Activity
Jun ’22
LineMark Does Not Respect .foregroundStyle Color choice
Working through the new Swift Chart framework and I am noticing LineMark does not seem to want to respect .foregroundStyle(.pink) (or any respective color) for more than one line. Apple's own Chart page lists an example that, when copied into Xcode 14 (beta 1) it does not render in preview as it does in their screenshot Data used: struct ProfitOverTime { var week: Int var profit: Double } let departmentAProfile: [ProfitOverTime] = [ .init(week: 1, profit: 21.5), .init(week: 2, profit: 19.2), .init(week: 3, profit: 18.4), .init(week: 4, profit: 21.0), .init(week: 5, profit: 19.7), .init(week: 6, profit: 14.7), .init(week: 7, profit: 22.1), .init(week: 8, profit: 18.0) ] let departmentBProfile: [ProfitOverTime] = [ .init(week: 1, profit: 5.7), .init(week: 2, profit: 12.0), .init(week: 3, profit: 11.9), .init(week: 4, profit: 18.0), .init(week: 5, profit: 15.9), .init(week: 6, profit: 16.7), .init(week: 7, profit: 12.1), .init(week: 8, profit: 19.0) ] Content View: struct ContentView: View {     var body: some View { Chart { ForEach(departmentAProfile, id: \.week) { LineMark( x: .value("Week", $0.week), y: .value("Profit A", $0.profit) ).foregroundStyle(.green) } ForEach(departmentBProfile, id: \.week) { LineMark( x: .value("Week", $0.week), y: .value("Profit B", $0.profit) ) .foregroundStyle(.green) } RuleMark( y: .value("Threshold", 20.0) ) .foregroundStyle(.teal) }     } } Produces
Replies
2
Boosts
0
Views
2.2k
Activity
Jun ’22
Auto zooming on data variation chart type & Axis breaks symbols
A lot of time when you plot a chart (say a bar chart here) for business you wants to emphasize the small variation between data, say daily you have roughly 5 millions messages sent but you need to visualize the 3k variations common each days. To utilize the landscape it's best for one to visualize not from zero but zooming in between 4.9m ~ 5.2m range instead of showing a slightly wiggling line. While we could likely (I haven't get to it) to customize our chart to do that it'd be a good and handy option for the standard charts and Swift Chart would auto-adjust the range. On top of it, being able to add standard axis break symbols would be a great help to keep it visualized and keep the chart honest.
Replies
0
Boosts
0
Views
893
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