Reputation: 897
Using ios-charts and I'm trying to figure out how to display a full width line chart using ios-chart. Currently my chart looks like the following below:
My Code looks like the following:
let chartView = LineChartView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height))
chartView.backgroundColor = UIColor.white
chartView.chartDescription?.enabled = false
chartView.dragEnabled = false
chartView.setScaleEnabled(false)
chartView.pinchZoomEnabled = false
chartView.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0)
chartView.legend.enabled = false
chartView.leftAxis.enabled = false
chartView.leftAxis.spaceTop = 0.4
chartView.leftAxis.spaceBottom = 0.4
chartView.rightAxis.enabled = false
chartView.drawGridBackgroundEnabled = false
chartView.clipValuesToContentEnabled = true
let xAxis = chartView.xAxis
xAxis.labelFont = UIFont(name: MegaTheme.fontName, size: 12.0)!
xAxis.labelTextColor = UIColor.black
xAxis.drawGridLinesEnabled = false
xAxis.drawAxisLineEnabled = true
xAxis.granularity = 1.0
xAxis.avoidFirstLastClippingEnabled = true
xAxis.wordWrapEnabled = true
xAxis.enabled = true
xAxis.labelPosition = .bottomInside
xAxis.labelCount = goal.progress.count + 1
chartView.animate(xAxisDuration: 1.5)
generateGoalLineChartData(chartView, goal: goal)
return chartView
Even when avoidFirstLastClippingEnabled enabled I still get first and last value clipped.
Upvotes: 1
Views: 2859
Reputation: 8341
For above Chart margin issue you need to comment below line or change value as per your requirements:
chartView.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0)
comment above line so Chart will use its default margin or use as per your requirement like below :
chartView.setViewPortOffsets(left: 20, top: 20, right: 20, bottom: 20)
Hope this will help you to set your viewPort.
Upvotes: 5