Swift Charts

RSS for tag

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

Swift Charts Documentation

Posts under Swift Charts tag

30 Posts
Sort by:
Post marked as solved
3 Replies
432 Views
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")                         }                     }                 }             }
Posted
by
ngb
Post not yet marked as solved
1 Replies
267 Views
I now watched all 4 charts WWDC22 videos. It looks like there is no pie chart support. Do I need to build such style by myself or is there a way to implement this in the new Swift Charts framework?
Posted
by
Post not yet marked as solved
0 Replies
145 Views
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?
Posted
by
Post not yet marked as solved
0 Replies
96 Views
Are PieCharts supported?
Posted
by
Post not yet marked as solved
0 Replies
146 Views
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.
Posted
by
Post not yet marked as solved
2 Replies
227 Views
Hi SwiftUI updates such as Charts are available to use now or till the new OS launches in coming fall ? Kindest Regards
Posted
by
Post not yet marked as solved
1 Replies
258 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
by
Post marked as solved
2 Replies
231 Views
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
Posted
by