最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

SwiftUI BarChart area spacing - Stack Overflow

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论