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

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.