SwiftUICharts icon indicating copy to clipboard operation
SwiftUICharts copied to clipboard

pointMarkers modifier causing X Axis not to be visible until scrolled

Open 1337domz opened this issue 3 years ago • 5 comments

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)
    }
    
}

1337domz avatar Dec 29 '21 15:12 1337domz

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

willdale avatar Jan 12 '22 20:01 willdale

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

1337domz avatar Jan 13 '22 20:01 1337domz

+1

MZC0829 avatar Jun 14 '22 09:06 MZC0829

I do see this issue on real devices.

mvolkmann avatar Aug 02 '22 16:08 mvolkmann

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.

mvolkmann avatar Aug 03 '22 16:08 mvolkmann