LineMark chart reverting Y axis

Dear all, I have a line chart and on the Y axis it shows values from 0 (bottom) to 20 (top). Now, I'd like to show value from 20 (bottom) to 1 (top).

Here below the code I used:

 Chart{
                                ForEach(andamento, id: \.posizione) { item in
                                    LineMark(
                                        x: .value("Giornata", item.giornata),
                                        y: .value("Posizione", item.posizione)
                                    )
                                    
                                    PointMark(
                                        x: .value("Giornata", item.giornata),
                                        y: .value("Posizione", item.posizione)
                                    )
                                    
                                    // We need .opacity(0) or it will
                                    // overlay your `.symbol`
                                    .opacity(0)
                                    .annotation(position: .overlay,
                                                alignment: .bottom,
                                                spacing: 10) {
                                        Text("\(item.posizione)")
                                            .font(.subheadline)
                                    }
                                }
                                .symbol(Circle())
                            }

Can anybody help me?

Thanks, A.

Accepted Reply

Did you try something like:

                                ForEach(andamento, id: \.posizione) { item in
                                    LineMark(
                                        x: .value("Giornata", item.giornata),
                                        y: .value("Posizione", 20 - item.posizione)  // May be need to adjust 20 to 21, if you want to end at 1
                                    )
                                    
                                    PointMark(
                                        x: .value("Giornata", item.giornata),
                                        y: .value("Posizione", 20 - item.posizione)
                                    )

Replies

Did you try something like:

                                ForEach(andamento, id: \.posizione) { item in
                                    LineMark(
                                        x: .value("Giornata", item.giornata),
                                        y: .value("Posizione", 20 - item.posizione)  // May be need to adjust 20 to 21, if you want to end at 1
                                    )
                                    
                                    PointMark(
                                        x: .value("Giornata", item.giornata),
                                        y: .value("Posizione", 20 - item.posizione)
                                    )

Hi Claude31, that works perfectly!

Thank you so much!

A.