Open HafizMuhammadMurtaza opened 1 year ago
I am giving the correct data for x and y axis, but sometimes line charts get flat, then after refresh it becomes in it normal position.
Following is my code of creating LineChartView
`import Charts import SwiftUI
struct MiniChartView: UIViewRepresentable { var entries: [ChartDataEntry]
typealias UIViewType = LineChartView func makeUIView(context: Context) -> LineChartView { let chart = LineChartView() chart.data = generateData() chart.legend.enabled = false chart.xAxis.drawGridLinesEnabled = false chart.leftAxis.drawGridLinesEnabled = false chart.chartDescription.enabled = false chart.xAxis.drawGridLinesEnabled = false chart.xAxis.drawLabelsEnabled = false chart.xAxis.drawAxisLineEnabled = false chart.rightAxis.enabled = false chart.leftAxis.enabled = false chart.drawBordersEnabled = false chart.legend.form = .none chart.isUserInteractionEnabled = false return chart } func updateUIView(_ uiView: LineChartView, context: Context) { uiView.data = generateData() } func generateData() -> LineChartData { let dataSet = LineChartDataSet(entries: entries) dataSet.lineDashLengths = nil dataSet.highlightLineDashLengths = nil dataSet.gradientPositions = [0, 40, 100] dataSet.lineWidth = 2 dataSet.circleRadius = 0 dataSet.drawCircleHoleEnabled = false dataSet.valueFont = .systemFont(ofSize: 0) dataSet.formLineDashLengths = nil dataSet.formLineWidth = 1 dataSet.formSize = 2 dataSet.mode = .cubicBezier let colorTop = UIColor(red: 50/255, green: 200/255, blue: 255/255, alpha: 1.0).cgColor let colorBottom = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.0).cgColor let gradientColors = [colorTop, colorBottom] as CFArray // Colors of the gradient let colorLocations: [CGFloat] = [0.6, 0.0] // Positioning of the gradient if let gradient = CGGradient.init(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: gradientColors, locations: colorLocations) { dataSet.fill = LinearGradientFill(gradient: gradient, angle: 90.0) // Set the Gradient dataSet.drawFilledEnabled = true } let data = LineChartData(dataSet: dataSet) return data }
}`
I am giving the correct data for x and y axis, but sometimes line charts get flat, then after refresh it becomes in it normal position.
Following is my code of creating LineChartView
`import Charts import SwiftUI
struct MiniChartView: UIViewRepresentable { var entries: [ChartDataEntry]
}`