TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your 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.