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

ios - How to increase spacing between labels and bars in chart - Stack Overflow

programmeradmin2浏览0评论

How do I increase the spacing between the labels and the bars?

    var body: some View {
        if sections.count > 4 {
            defaultBody().aspectRatio(1, contentMode: .fill)
        } else {
            // when there are too little items, aspect ratio above makes the chart look too spaced out, so we don't use it
            defaultBody()
        }
    }
    
    private func defaultBody() -> some View {
        Chart(sections) { section in
            BarMark(x: .value("Price", section.header.totalPrice * progress),
                    y: .value("Category", section.header.name))
            .foregroundStyle(Theme.accentSec)
            .position(by: .value("Alignment", 0))
        }
        .chartLegend(.hidden)
        .chartXAxis(.hidden)
        .chartXScale(domain: .automatic(dataType: Float.self, modifyInferredDomain: { $0 = [0, max] }))
        .chartYAxis {
            AxisMarks { _ in
                AxisValueLabel()
                    .foregroundStyle(Color.black)
            }
        }
        .onAppear {
            animateChart()
        }
    }
发布评论

评论列表(0)

  1. 暂无评论