Hello:
I have a chart that looks like this:
Chart {
ForEach(measurements) { measurement in // iterate through all of the measurement data
ForEach(measurement.values.indices, id: \.self) { index in
let datapoint = measurement.values[index]
if showData[measurement.name]![index]{
BarMark(x: .value(xValueLabel, datapoint.dateTime, unit: .hour), y: .value(measurement.name.description, datapoint.value), width: 10.0)
.foregroundStyle(by: .value("Measurement", measurement.name.description))
.clipShape(RoundedRectangle(cornerRadius: 16))
} // end if
} // end nested foreach
} //end parent foreach
if let chartSelDates { //shows the details for the selected date
RectangleMark(
xStart: .value("Date",chartSelDates.lowerBound),
xEnd: .value("Date",chartSelDates.upperBound),
yStart: .value("Value", 0),
yEnd: .value("Value", yAxisScale.last!))
.foregroundStyle(.gray.opacity(0.4))
.zIndex(-1)
.annotation(position: .top, spacing: 0, overflowResolution: .init(x: .fit(to: .chart), y: .disabled)) {
content
.fixedSize(horizontal: true, vertical: false)
}
} // end if
} // end chart
This ends up producing a chart that looks like this. Notice how the last point overflows beyond the y-axis labels.
If I remove the "unit: .hour" bit from the line "BarMark(x: .value(xValueLabel, datapoint.dateTime, unit: .hour), y: .value(measurement.name.description, datapoint.value), width: 10.0)" then I get this chart
Can someone point me in the right direction as to what I should be changing to the bars stay inside of the chart space?