Im seeing "Charts: Falling back to a fixed dimension size for a mark. Consider adding unit to the data or specifying an exact dimension size." while using charts on SwiftUI. Does anyone knows what this error is talking about? I couldn't find it online.

Chart {
    ForEach(data) { dataPoint in
        BarMark(x: .value("Day", dataPoint.day, unit: .day),
                y: .value("Minutes", dataPoint.number))
    }
}
.chartXAxis {
    AxisMarks(preset: .aligned){ _ in
    AxisValueLabel()
             }
           }
.chartYAxis {
    AxisMarks(preset: .automatic){ _ in
    AxisValueLabel()
    AxisGridLine()
             }
            }
1

There are 1 best solutions below

0
Fran On BEST ANSWER

Ok after more research I found what was missing about the "fixed dimension size for a mark" It gives a fixed size for each bar as the error says and it's done like:

BarMark(x: .value("Day", dataPoint.day),
y: .value("Feeds", dataPoint.number), width: 8)

The "width: 8" part. And it looks like: enter image description here

The "adding unit to the data". It should be a Date unit and you have to be working with that type on your Data. It gives an automatic width depending on how much data do you have. Is done like this:

ForEach(data) { dataPoint in
   BarMark(x: .value("Day", dataPoint.day, unit: .day),
           y: .value("Number", dataPoint.number))
               }

And looks something like this: enter image description here