Hi,
I'm currently wrestling with the .chartXScale(domain:)
modifier in order to get my Chart
to display correctly. The basics of the Chart
look like this.
Chart(measurements, id: \.timestamp) { measurement in
if let total = measurement.production?.total {
BarMark(
x: .value(
"Timestamp",
measurement.timestamp,
unit: .weekOfYear,
calendar: .current
),
y: .value(
"Solar production",
total
)
)
}
}
As anyone familiar with Charts can see, I sort data into columns based on what week of the year the measurements belong to. Some of them can be null, and when they are, I still want space in the Chart
where a BarMark
would've been to be taken up, like week number 4 in this example chart (in which I've defaulted all measurements that are null in week 4 to 0, for demonstration purposes):
To achieve that, as I understand, I'm meant to use the .chartXScale(domain:)
modifier, but when I apply the following modifier...
.chartXScale(domain: firstDayOfMonth...firstDayOfNextMonth)
... (where the domain is from the first day of the month to the first day of the next month), to the code above, I end up with this weird half step when the last week of measurements are all null:
For reference, here's how the domain dates are set in my minimum reproducible example:
firstDayOfMonth = Calendar.current.date(from: Calendar.current.dateComponents([.year, .month], from: .now))!
firstDayOfNextMonth = Calendar.current.date(byAdding: .month, value: 1, to: firstDayOfMonth)!
Am I misusing this modifier somehow, or is this a bug? Would love some help figuring this out, thanks!