全宽图表会在ios图表中截断左右值

时间:2018-02-12 23:23:20

标签: ios swift ios-charts

使用ios-charts,我试图弄清楚如何使用ios-chart显示全宽折线图。目前我的图表如下所示:

ios-charts

我的代码如下所示:

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

即使启用了AvoidFirstLastClippingEnabled,我仍然可以获得第一个和最后一个值。

1 个答案:

答案 0 :(得分:1)

对于上面的图表保证金问题,您需要在下面注释或根据您的要求更改值:

chartView.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0)

在上面注释,因此Chart将使用其默认保证金或根据您的要求使用,如下所示:

chartView.setViewPortOffsets(left: 20, top: 20, right: 20, bottom: 20)

希望这可以帮助您设置viewPort。