Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid disappears after navigating away and returning to a view containing a chart #2

Closed
jeffgrann opened this issue Jan 30, 2021 · 3 comments

Comments

@jeffgrann
Copy link

SwiftUICharts-Grid.mp4
import SwiftUI
import SwiftUICharts

struct ProgressMain: View {
    let data : ChartData = weekOfData()
        
    var body: some View {

            LineChart()
                .xAxisGrid()
                .yAxisGrid()
                .xAxisLabels()
                .yAxisLabels()
                .environmentObject(data)
                .frame(height: 200, alignment: .center)
                .padding()
    }
}

extension ProgressMain {
    
    static func weekOfData() -> ChartData {
        
        let data : [ChartDataPoint] = [
            ChartDataPoint(value: 20, xAxisLabel: "Jun 18"),
            ChartDataPoint(value: 90),
            ChartDataPoint(value: 100),
            ChartDataPoint(value: 75),
            ChartDataPoint(value: 160),
            ChartDataPoint(value: 110),
            ChartDataPoint(value: 90, xAxisLabel: "Sep 20")
        ]
        
        let gridStyle = GridStyle(numberOfLines : 6,
                                  lineColour    : Color(.lightGray).opacity(0.25),
                                  dash          : [4])
        
        let chartStyle = ChartStyle(xAxisGridStyle      : gridStyle,
                                    yAxisGridStyle      : gridStyle,
                                    yAxisNumberOfLabels : 1)
        
        let lineStyle = LineStyle(colour      : .accent,
                                  lineType    : .line,
                                  strokeStyle : StrokeStyle(lineWidth: 3, lineCap: .round, lineJoin: .round))
        
        return ChartData(dataPoints : data,
                         chartStyle : chartStyle,
                         lineStyle  : lineStyle)
    }
}
@willdale
Copy link
Owner

Grid fixed in v1.0.6.

Thanks.

@jeffgrann
Copy link
Author

Works like a champ. Thank you so much for this wonderful SwiftUI library. Version 1.0 is first class!

@willdale
Copy link
Owner

Excellent, glad you like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants