Ran*_*dle 1 ios swift ios-charts
使用ios-charts,我试图弄清楚如何使用 ios-chart 显示全宽折线图。目前我的图表如下所示:
我的代码如下所示:
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
Run Code Online (Sandbox Code Playgroud)
即使启用了voidFirstLastClippingEnabled,我仍然会剪切第一个和最后一个值。
对于上面的图表保证金问题,您需要在下面注释行或根据您的要求更改值:
chartView.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0)
Run Code Online (Sandbox Code Playgroud)
注释上方的行,以便图表将使用其默认边距或根据您的要求使用,如下所示:
chartView.setViewPortOffsets(left: 20, top: 20, right: 20, bottom: 20)
Run Code Online (Sandbox Code Playgroud)
希望这能帮助您设置视口。
| 归档时间: |
|
| 查看次数: |
2783 次 |
| 最近记录: |