admin管理员组

文章数量:1435859

I have a BarChart made with the SwiftUI Chart API. The bar is pretty close to what I want it to look like, but the last details elude me. Here's the current version of the chart.

What I want is to have the bars closer together in order to create some space on the outside of the bars. To be clear, I want the tick lines to remain where they are, just having the bars "tighter". (I want to create space where the black circles are).

Here's the part of the code that I think is relevant:

Chart {
    ForEach(chartData) { data in
        BarMark(x: .value("X value", data.x),
                y: .value("Y value", data.y),
                width: 30)
               .annotation(position: .automatic, alignment: .top) {
                   Text("\(data.y)")
                }
                .clipShape(RoundedRectangle(cornerRadius: 8))
                }

        RuleMark(y: .value("average", averageMark))
            .lineStyle(StrokeStyle(lineWidth: 2, dash: [5, 5]))
            .annotation(position: .top,
                        alignment: .trailing,
                        spacing: 0.0) {
                    Text("★")
                }
        }
    // more Chart code
    }
}

Code is simplified: I omitted the x and y axis builders and styling.

Another thing that would be nice is if I could have the '*' (which is the RuleMark) outside of the chart.

本文标签: SwiftUI BarChart area spacingStack Overflow