ios Swift 图表问题
ios Swift Chart issue
我使用图表 iOS 库(https://github.com/danielgindi/Charts)并且我有以下代码:
import UIKit
import Charts
class ChartsViewController: UIViewController , ChartViewDelegate{
var lineChartView: LineChartView?
let months = ["Jan" , "Feb", "Mar", "Apr", "May", "June", "July", "August", "Sept", "Oct", "Nov", "Dec"]
let dollars1 = [1453.0,2352,5431,1442,5451,6486,1173,5678,9234,1345,9411,2212]
override func viewDidLoad() {
super.viewDidLoad()
self.lineChartView = LineChartView(frame: CGRectMake(50, 70, 300, 300))
self.lineChartView!.delegate = self
self.lineChartView!.descriptionText = "Tap node for details"
self.lineChartView!.drawGridBackgroundEnabled = false
self.lineChartView!.descriptionTextColor = UIColor.whiteColor()
self.lineChartView!.noDataText = "No data provided"
setChartData(months)
self.view.addSubview(self.lineChartView!)
}
func setChartData(months : [String]) {
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for var i = 0; i < months.count; i++ {
yVals1.append(ChartDataEntry(value: dollars1[i], xIndex: i))
}
let set1: LineChartDataSet = LineChartDataSet(yVals: yVals1, label: "First Set")
set1.lineWidth = 10.0
set1.circleRadius = 0.0 // the radius of the node circle
set1.fillColor = UIColor.redColor()
set1.highlightColor = UIColor.yellowColor()
set1.drawCircleHoleEnabled = false
set1.drawVerticalHighlightIndicatorEnabled = false
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
dataSets.append(set1)
let data: LineChartData = LineChartData(xVals: months, dataSets: dataSets)
data.setValueTextColor(UIColor.whiteColor())
self.lineChartView!.data = data
}
我明白了:
https://postimg.org/image/6z6nk5nkn/
我的问题是:
我想删除背景上的网格(垂直线和水平线),但我做不到,因为我在官方库文档中找不到任何内容。
你能帮帮我吗?
您可以使用此代码禁用网格:
lineChartView.xAxis.drawGridLinesEnabled = false
lineChartView.leftAxis.drawGridLinesEnabled = false
self.lineChartView.leftAxis.drawGridLinesEnabled = false
self.lineChartView.xAxis.drawGridLinesEnabled = false
会完成任务的。
我使用图表 iOS 库(https://github.com/danielgindi/Charts)并且我有以下代码:
import UIKit
import Charts
class ChartsViewController: UIViewController , ChartViewDelegate{
var lineChartView: LineChartView?
let months = ["Jan" , "Feb", "Mar", "Apr", "May", "June", "July", "August", "Sept", "Oct", "Nov", "Dec"]
let dollars1 = [1453.0,2352,5431,1442,5451,6486,1173,5678,9234,1345,9411,2212]
override func viewDidLoad() {
super.viewDidLoad()
self.lineChartView = LineChartView(frame: CGRectMake(50, 70, 300, 300))
self.lineChartView!.delegate = self
self.lineChartView!.descriptionText = "Tap node for details"
self.lineChartView!.drawGridBackgroundEnabled = false
self.lineChartView!.descriptionTextColor = UIColor.whiteColor()
self.lineChartView!.noDataText = "No data provided"
setChartData(months)
self.view.addSubview(self.lineChartView!)
}
func setChartData(months : [String]) {
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for var i = 0; i < months.count; i++ {
yVals1.append(ChartDataEntry(value: dollars1[i], xIndex: i))
}
let set1: LineChartDataSet = LineChartDataSet(yVals: yVals1, label: "First Set")
set1.lineWidth = 10.0
set1.circleRadius = 0.0 // the radius of the node circle
set1.fillColor = UIColor.redColor()
set1.highlightColor = UIColor.yellowColor()
set1.drawCircleHoleEnabled = false
set1.drawVerticalHighlightIndicatorEnabled = false
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
dataSets.append(set1)
let data: LineChartData = LineChartData(xVals: months, dataSets: dataSets)
data.setValueTextColor(UIColor.whiteColor())
self.lineChartView!.data = data
}
我明白了:
https://postimg.org/image/6z6nk5nkn/
我的问题是:
我想删除背景上的网格(垂直线和水平线),但我做不到,因为我在官方库文档中找不到任何内容。
你能帮帮我吗?
您可以使用此代码禁用网格:
lineChartView.xAxis.drawGridLinesEnabled = false
lineChartView.leftAxis.drawGridLinesEnabled = false
self.lineChartView.leftAxis.drawGridLinesEnabled = false
self.lineChartView.xAxis.drawGridLinesEnabled = false
会完成任务的。