Post not yet marked as solved
I'm experimenting with replacing my graph implementation with SwiftCharts. One issue I ran into is that I'm graphing stock data, but that data is only present during trading hours. In the screenshot I included, you can see my implementation on top vs the SwiftCharts version as well as the stocks app.
Because trading is from 9:30AM-4:00PM, if the times are graphed linearly, there will be large gaps for nights and weekends.
The way I implemented this before was to treat each "tick" of data as equal width. .chartXScale(type: .category) seems like it would do something similar, but if I try that I get the following error:
Fatal error: the specified scale type is incompatible with the data values and visual property.
Post not yet marked as solved
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?
Post not yet marked as solved
How do I make the chart linemark and areamark extend to the edges of the plot area? I have looked at the Food Truck app and can't find how it is achieved. The screenshot attached points to the gaps I'd like to eliminate.
Post not yet marked as solved
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?
Post not yet marked as solved
Hi
SwiftUI updates such as Charts are available to use now or till the new OS launches in coming fall ?
Kindest Regards
Post not yet marked as solved
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?
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
Post not yet marked as solved
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.
Post not yet marked as solved
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?