0

Anyone run into problems with SwiftUI Charts using a RectangleMark where the foregroundStyle color doesn't render any opacity for large datasets? This doesn't happen when my dataSet is small.

Here I have my chart code as well as the method I call whenever I detect my drag gesture.

Chart(item.selectedStockChart, id: \.id) { data in
    LineMark(x: .value("Index", data.formattedDate), y: .value("Value", data.close))
    ...

    if let (start, end) = range, enablePriceDrag {
        RectangleMark(xStart: .value("Selection Start", start),
                      xEnd: .value("Selection End", end))
            .foregroundStyle(.red.opacity(0.1))
    }
}

private func onChangeDrag(value: DragGesture.Value, chartProxy: ChartProxy, geometryProxy: GeometryProxy) {
    showStartingPriceLabel = true
    /// Find the x coordinates in the chart's plot area.
    let startX = value.startLocation.x
    let currentX = value.location.x

    if let startDate: Date = chartProxy.value(atX: startX),
       let currentDate: Date = chartProxy.value(atX: currentX),
       currentDate > startDate
    {
        range = (startDate, currentDate)
    }
}

Wrong Result Where Rectangle Mark Has No Opacity UnIntended Result

Correct Result But Only with Small DataSet enter image description here

Ken White
  • 123,280
  • 14
  • 225
  • 444
Kenny Ho
  • 409
  • 3
  • 16

0 Answers0