UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Need advise on grid lines displayed in a chart

Forums > SwiftUI

Hello Everyone, I have a chart related question. See thge chart in the image linked below. You can see the horizontal gridlines displayed under each bar. I'd like to get rid of them but I cant figure out how to do that. I've tried to add .chartXAxis(.hidden), that seems to remove them, but it also removes the date from the Y axis. Any ideas?

https://imgur.com/a/WRIYB8B

Thank you for any advise!

  Chart {
            ForEach(last5Crawls) { crawlData in
                BarMark(
                    x: .value("Avg. Discovered by Google", crawlData.knownUrls),
                    y: .value("Crawl", crawlData.crawlDateLaunched),
                    width: 20
                )
                .foregroundStyle(Color.yellow.gradient)
                .cornerRadius(10)
                .annotation(position: .trailing) {
                    Text("\(crawlData.knownUrls) (\(crawlData.knownUrlsChange, specifier: "%.2f")%)")
                        .font(.system(size: 10, weight: .semibold))
                        .foregroundColor(crawlData.knownUrlsChange < 0 ? .red : .green)
                }
            }
        }
        .frame(minHeight: 180)
        .listRowSeparator(.hidden)
        .chartForegroundStyleScale([
            "All Pages": Color.yellow
        ])
        .chartLegend(position: .top, alignment: .bottomLeading)
        .chartXAxis(.hidden)

2      

Try this modifier

.chartYAxis {
  AxisMarks(stroke: StrokeStyle(lineWidth: 0))
}

or

.chartYAxis {
    AxisMarks { _ in
        AxisValueLabel()
    }
}

3      

Genius, pure genius. Thank you @ygeres. Thank you very much!

This worked for me

.chartYAxis {
  AxisMarks(stroke: StrokeStyle(lineWidth: 0))
}

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.