willdale / SwiftUICharts

A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS and has accessibility features built in.
MIT License
824 stars 100 forks source link

pointMarkers modifier causing X Axis not to be visible until scrolled #154

Open 1337domz opened 2 years ago

1337domz commented 2 years ago

A strange bug - with the attached code if you comment out the pointMarkers modifier the X Axis displays as expected, but with it in it appears not to be visible. If you wrap the chart in a ScrollView and trigger some motion, the X Axis does appear after being scrolled.

Screenshot 2021-12-29 at 15 47 11
struct ContentView: View {

    let data: LineChartData = chartData()

    var body: some View {
        ScrollView {
                LineChart(chartData: data)
                    // Removing the pointMarkers modifier, and the X axis is always visible
                    .pointMarkers(chartData: data)
                    .xAxisLabels(chartData: data)
                    .yAxisLabels(chartData: data)
                    .id(data.id)
                    .frame(height: 200)
                    .padding()
        }
    }

    static func chartData() -> LineChartData {
        let dailyData = LineDataSet(dataPoints: [
            LineChartDataPoint(value: 12000, xAxisLabel: "M", description: "Monday"   ),
            LineChartDataPoint(value: 10000, xAxisLabel: "T", description: "Tuesday"  ),
            LineChartDataPoint(value: 8000 , xAxisLabel: "W", description: "Wednesday"),
            LineChartDataPoint(value: 17500, xAxisLabel: "T", description: "Thursday" ),
            LineChartDataPoint(value: 16000, xAxisLabel: "F", description: "Friday"   ),
            LineChartDataPoint(value: 11000, xAxisLabel: "S", description: "Saturday" ),
            LineChartDataPoint(value: 9000 , xAxisLabel: "S", description: "Sunday"   ),
        ])

        return LineChartData(dataSets: dailyData)
    }

}
willdale commented 2 years ago

Hey @1337domz, sorry for the late reply!

Is this just in the previews? I can't replicate it on a device or a simulator but I can when in a preview.

Heres another issue #89 to do with x axis labels in previews.

Thanks, Will

1337domz commented 2 years ago

Hey @willdale

Weirdly this happens on simulator but no on device. I have had issues with the library and disappearing X-axis on device though, and I thought I had found a minimum reproducible case but maybe not? Maybe there are multiple issues?

Here is it happening in the simulator though:

Xcode 13.2.1 iOS 15.2 Library added via SPM

https://user-images.githubusercontent.com/5438325/149403296-e3d2ee79-5eca-4229-9b86-67ec649e7f0d.mp4

MZC0829 commented 2 years ago

+1

mvolkmann commented 1 year ago

I do see this issue on real devices.

mvolkmann commented 1 year ago

Actually, I see this issue regardless of whether I call .pointMarkers. My chart displays x-axis labels initially. But all subsequent charts I display are missing the x-axis labels until I drag the left edge of the screen to the right a bit and let go. Then the labels appear.