gianni gianni -5 years ago 357
Swift Question

ios Swift Chart issue

I use Charts iOS library( and I have this code :

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() {

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"

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]()
let data: LineChartData = LineChartData(xVals: months, dataSets: dataSets)
self.lineChartView!.data = data

and I get this :

My problem is this :

I want to delete the grid on background(vertical and horizontal lines) but I dont be able because I dont find anything in the official library documentation.

Can you help me?

Answer Source
self.lineChartView.leftAxis.drawGridLinesEnabled = false
self.lineChartView.xAxis.drawGridLinesEnabled = false

will do the job.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download